Seaborn.diverging_palette() method



Seaborn.diverging_palette() method is used to make a diverging plot between two HUSL colors. HUSL color system is an alternative to the HSL color system. It is currently called as HSLuv System.

The choose_diverging_palette() function helps us use this method interactively with the help of the IPython notebook.

Syntax

Following is the syntax of the diverging_palette() method −

seaborn.diverging_palette(h_neg, h_pos, s=75, l=50, sep=1, n=6, center='light', as_cmap=False)

Parameters

The parameters of this method are as follows.

S.No Parameter and Description
1 H_neg,h_pos

Takes floating values between 0 and 359 and is the anchor hyes for negative and positive extends of the maps.

2 S

Takes float values between 0 and 100 and is the anchor saturation for both extends of the map.

3 L

Takes float values between 0 and 100 and is the anchor lightness for both extends of the map.

4 As_cmap

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

5 Sep

Takes integer values is the size of the intermediate region,

6 Center

Takes light or dark as values and determines if the center of the palette is light or dark

7 N

Takes int values and is the number of colors in the palette if cmap is not returned.

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 the of a brown to green palette. To do so, we will pass h_pos and h_neg values and then the number of colors to be produced in the list of RGB tuples. The following line of code can be used.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.diverging_palette(200, 20, n=15))
plt.show()

Output

the output is as follows,

seaborn_diverging_palette_method

Example 2

In this example. We will generate another set of colors just like the above case. In this case we will get a blue-pink palette generated. but we will also understand the usage of the sep parameter which determines the size of the intermediate region.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.diverging_palette(250, 349, n=15,sep=200))
plt.show()

Output

the output is as follows,

seaborn_diverging_palette

Example 3

We will create a blue to red toned palette with white in between by passing h_pos, h_neg, lightness and saturation parameters along with the number of colors in the produced output which in this case is 15.

import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.diverging_palette(250, 10, n=15,s=50,l=20))
plt.show()

Output

The output is as follows −

diverging_palette
seaborn_color_palettes_introduction.htm
Advertisements