Seaborn.dark_palette() method



Seaborn.dark_palette() method is used to make a sequential palette that blends from dark colors to lighter colors. This palette is good for data that range between relatively low to high values.

The color parameter in this method can be passed in various ways, for instance, defining all the colors in the matplotlib, several seaborn-handled additional color spaces and the database of xkcd survey’s named colors.

With the help of IPython notebook, the color palette can also be chosen with the help of choose_dark_palette() function.

Syntax

Following is the syntax of the dark_palette() method −

seaborn.dark_palette(color, n_colors=6, reverse=False, as_cmap=False, input='rgb')

Parameters

The parameters of the seaborn.dark_aplette() are shown below.

S.No Parameter and Description
1 Color

Takes base color fo high values and it is either a hex, an rgb tuple or an html color name.

2 N_color

Takes interger values and determines the number of colors in the palette. It is an optional parameter.

3 Reverse

This optional parameter takes Boolean values and If true reverses the direction of the blend.

4 As_cmap

This optional parameter takes Boolean values and if true returns an matplotlib colormap.

5 input

This takes inputs as rgb, hls, husl or xkcd. This is the color space rto tinterpret the input color.

Return value

This method returns a list of rgb tuples or a matplotlib colormap. Now we will see the working of this method in the following examples.

Example 1

in this example, we will see how the dark_paleetee method works. Inorder to produce an output, the palplot() method in seaborn is used and this method produces a series of colors that are part fof the palette passed as argument. We will produce the colors of the purple color palette in this example.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.dark_palette("purple"))
plt.show()

Output

The output is as follows −

seaborn_dark_palette_method

Example 2

In this example, we will use the reverse optional parameter and this parameter takes bolean values and if true is passed ot it, the colors are shown in the reverse order. We will pass the color teal to it.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.dark_palette("teal", reverse=True))
plt.show()

Output

The output produced is as follows −

dark_palette_method

Example 3

In this example, we will get a palette from the HUSL color seed. This can be done by passing a tuple to the input optional parameter. In this case, we will pass the colors relating to the HUSL color seed. The following line of code can be referred to.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.dark_palette((240, 80, 90), input="husl"))
plt.show()

Output

The output is as follows −

dark_palette

Example 4

In this example, we will see the generation of a heatmap that has a dark palette in it. We will create a numpy array as the range for the heatmap creation and then we will use a color to create a dark palette heatmap.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
from numpy import arange
x = arange(64).reshape(8, 8)
cmap = sns.dark_palette("#495C83")
ax = sns.heatmap(x, cmap=cmap)
plt.show()

Output

The output produced is as follows −

seaborn_dark_palette
seaborn_color_palettes_introduction.htm
Advertisements