Seaborn.color_palette() method



The Seaborn.color_palette() method returns a palette defined by a list of colors or a continuous colormap.

Plots can be colored using the seaborn color palette(), which will be demonstrated. We may generate the point with various colors using the palette. In the sample below, we can see that the palette is capable of producing various color map values.

Syntax

Following is the syntax of the color_palette() method −

seaborn.color_palette(palette=None, n_colors=None, desat=None, as_cmap=False)

Parameters

The parameters of the seaborn.color_palette() are describes below.

S.No Parameter and Description
1 Palette

The palette that is to be set.

2 n_colors

Number of colors in the cycle.

3 Desat

Proportion to de-saturate each color by.

4 As_cmap

Takes Boolean values and if true returns a matplotlib color map.

Return Value

A palette defined by a list of colors or a continuous colormap.

Example 1

In this example we will see how to use the color_palette() method available in seaborn. We will pass a matplotlib palette as an argument to the method and it will return a series of colors that are part of that palette. This method can be used to check the colors available is a particular palette. Later, the, palete can be set using the set_palette() method in seaborn and plots can be plotted.

Here, we will see the flare palette by passing it as an argument to the color_palette() method.

import seaborn as sns
import matplotlib.pyplot as plt
sns.palplot(sns.color_palette("flare"))
plt.show()

Output

The output produced is as follows and it contains all the colors that are paet of the flare pallete.

pallete

Example 2

in this example we will pass an integer value along with the palette name to the color_palette() method and this integer is the n_colors values which will display that many colors of the palette.

import seaborn as sns
import matplotlib.pyplot as plt
sns.palplot(sns.color_palette("flare", 20))
plt.show()

Output

The output produced is as follows −

colors

Example 3

In this example, we will make use of the as_cmap function and pass the value True to it. The below line of code can be used to do so.

sns.color_palette("flare", as_cmap=True)

Output

The output obtained is as follows −

seaborn color palette
seaborn_color_palettes_introduction.htm
Advertisements