Seaborn.light_palette() method



Seaborn.light_palette() method is used to make a sequential palette that blends from light to color. This style of palette works well for data that span the spectrum between fascinating high values and relatively dull low values.

All options for specifying a color in matplotlib as well as a number of extra color spaces supported by seaborn can be used to specify the color parameter. You can also utilize the XKCD color survey's database of named colors.

Syntax

Following is the syntax of the light_paleetew() method −

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

Parameters

The parameters of this Seaborn method are described 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 integer 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 light_palettee 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 and the colors are lighter in shade. 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.light_palette("purple"))
plt.show()

Output

The output is as follows −

Example 2

In this example, we will use the reverse optional parameter and this parameter takes Boolean values and if true is passed ot it, the colors are shown in the reverse order. We will pass the color teal to it. The colors go from darker to lighter shade.

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

Output

The output produced is as follows −

light_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 og 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 −

light_palette

Example 4

In this example, we will see the generation of a heatmap that has a light 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 light 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.light_palette("#495C83")
ax = sns.heatmap(x, cmap=cmap)
plt.show()

Output

the output produced is as follows,

seaborn_light_palette.jpg
seaborn_color_palettes_introduction.htm
Advertisements