VOOZH about

URL: https://www.geeksforgeeks.org/python/seaborn-color-palette/

⇱ Seaborn - Color Palette - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Seaborn - Color Palette

Last Updated : 8 Apr, 2025

In this article, We are going to see seaborn color_palette(), which can be used for coloring the plot. Using the palette we can generate the point with different colors.

Example:

Output:

👁 color-palette
Color Palette

Explanation:

  • sns.set_palette("Set2"): This sets the color palette to "Set2", one of Seaborn's predefined color palettes.
  • sns.barplot(): This creates a bar plot using the data with the selected color palette.
  • plt.show(): This displays the plot.

Syntax:

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

Parameters:

  • palette: Name of palette or None to return current palette.
  • n_colors: Number of colors in the palette.
  • desat: Proportion to desaturate each color.

Returns: list of RGB tuples or matplotlib.colors.Colormap

Seaborn Color Palette Types

Seaborn offers several predefined color palettes that can be broadly classified into different categories based on their intended use and the types of visualization.

We can classify the different ways for using color_palette() types −

  • Qualitative
  • Sequential
  • Diverging

1. Qualitative

A qualitative palette is used when the variable is categorical in nature, the color assigned to each group need to be distinct. Each possible value of the variable is assigned one color from a qualitative palette within a plot as shown in figure.

👁 Image

Output:

👁 Image

2. Sequential

In sequential palettes color moved sequentially from a lighter to a darker. When the variable assigned to be colored is numeric or has inherently ordered values, then it can be depicted with a sequential palette as shown in figure.

👁 Image

Output:

👁 Image

3. Diverging

When we work on mixed value like +ve and -ve(low and high values) then diverging palette is the best suit for visualization.

👁 Image

Output:

👁 Image

Let's understand this with some examples:

In the below example we have used sns.color_palette() to construct a colormap and sns.palplot() to display the colors present in the colormap with "deep" attributes.

Output:

👁 Image

Example 2: In this example, we have used sns.color_palette() to construct a colormap and sns.palplot() to display the colors present in the colormap with "muted" attributes.

Output:

👁 Image

Example 3: In this example, we have used sns.color_palette() to construct a colormap and sns.palplot() to display the colors present in the colormap with "bright" attributes.

Output:

👁 Image

Example 4: In this example, we have used sns.color_palette() to construct a colormap and sns.palplot() to display the colors present in the colormap with "dark" attributes.

Output:

👁 Image

In this example, we have used sns.color_palette() to construct a colormap and sns.palplot() to display the colors present in the colormap with "BuGn_r" attributes.

Output:

👁 Image

If we want to create our own color palette and set it as the current color palette , we can do as following:

Output:

👁 Image
Comment
Article Tags: