Seaborn.husl_palette() method



The Seaborn.husl_palette() method is used to get a set of evenly spaced colors that are a part of the HUSL color space.

The HUSL color space defines the colors based on their hue, saturation and lightness. These hues are evenly dispered along a circular path, resulting in a palette that will be appropriate for categorical or cyclical data.

This function uses a nonlinear color space that is more perceptually uniform, but it is otherwise similar to hls_palette() method. The values of HSL should be between 0 and 1 always.

Syntax

Following is the syntax of the husl_palette() method −

seaborn.husl_palette(n_colors=6, h=0.01, s=0.9, l=0.65, as_cmap=False)

Parameters

The parameters of the husl palette method are described below.

S.No Parameter and Description
1 n_colors

Number of colors in the cycle.

2 h

Takes floating point numbers and is the first hue of the color cycle.

3 s

Takes floating point value is the saturation of the colors.

4 l

Takes floating point value and it is the lightness of the colors.

Return Value

It returns a list of RGB tuples a matplotlib colormap.

Example 1

In this example, we will understand the working of husl_palette() method. This method basically allows the user to create a custom palette by changing the hue, lightness and saturations of the colors. To plot the custom created palette, palplot() method is used.

This seaborn.palplot() method enables the user to plot a custom palette and see the pantones that are part of a particular palette. The difference between the color_palette and the palplto() method are that the color_palette() method plots the colors of the matplotlib palettes whereas the palplot() method is used to plot custom palettes.

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

Output

The output obtained is as follows −

seaborn husl palette method

Example 2

In this example, we will pass the hue value to the husl_paletee() method along with the n_colors value. Here, the hue value is set to 0.4 which is the value of the first hue in the custom series of colors.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.husl_palette(15,h=0.4))
plt.show()

Output

The output obtained is the following series of colors −

husl palette method

Example 3

Here, we will pass the saturation value along with the n-colors value to the method. The saturation is set to 0.2 in this example.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.husl_palette(10, s=.2))
plt.show()

Output

The output produced is as follow −

husl_palette

Example 4

here, we will pass the lightness value along with the n_colors value to the method. The lightness is set to 0.5 in this example.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.husl_palette(10, l=.5))
plt.show()

Output

The output produced is as follows −

seaborn husl palette

Example 5

Here, we will pass all the parameters to the husl_palette() method and later plot the colors.

import seaborn as snsn
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.husl_palette(10, l=.7,s=.5,h=0.1))
plt.show()

Output

The output produced is as follows −

husl_palette_color
seaborn_color_palettes_introduction.htm
Advertisements