Changing the color palette

Let's move on and change the color palette to see how it impacts the plot's colors. The following code sets the color palette to bright (one of seaborn's predefined palettes):

sns.set_palette("bright")

Let's see how it changes our plot's colors with the following command:

sns.boxplot(data=df);

The output should now look like the following screenshot:

As you can see, our plot's color scheme has completely changed due to the new palette we set. bright is not the only predefined color palette in seaborn; there are a few others, including deep, muted, pastel, bright, dark, and colorblind, as follows:

sns.palplot(sns.color_palette("deep", 7))
sns.palplot(sns.color_palette("muted", 7))
sns.palplot(sns.color_palette("pastel", 7))
sns.palplot(sns.color_palette("bright", 7))
sns.palplot(sns.color_palette("dark", 7))
sns.palplot(sns.color_palette("colorblind", 7))

The output of each palette is as follows:

Seaborn also has the ability to set Matplotlib's colormaps as color palettes; for example:

sns.palplot(sns.color_palette("RdBu", 7))
sns.palplot(sns.color_palette("Blues_d", 7))

The output from the preceding command is as follows:

Now let's use one of the Matplotlib colormaps as a color palette; we do this with the following command:


sns.set_palette("Blues_d")

Here, we are setting the palette to Blues_d, which is a Matplotlib colormap. Let's now redraw our plot with the following code to see its impact:

sns.boxplot(data=df);

The output from the preceding command should like the following screenshot:

As you can see, our plot now has a color palette from the blue colormap.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.99.120