Get startedGet started for free

Colors in Seaborn

1. Colors in Seaborn

Color is an extremely important component in creating effective visualizations. Different types of data can be interpreted more effectively by using the correct color palettes. In addition, around 8% of the population is affected by color blindness of some form, so using palettes that are tailored to those users is very important. Seaborn has several functions for creating, viewing, and configuring color palettes. Effectively understanding and using these functions can greatly increase the impact of your plots.

2. Defining a color for a plot

Since Seaborn is built on top of matplotlib, it is able to interpret and apply matplotlib color codes. By using the familiar sns.set() function with color codes equals True, any matplotlib color codes will be appropriately mapped to the Seaborn palette. Here is an example of plotting our displot() using a 'g' for green.

3. Palettes

As shown in the previous slide, we can assign specific colors to a plot. However, this can be tedious when there are many items that must be encoded with color. Seaborn makes this task much easier by allowing us to set a palette of colors that can be cycled through in a plot. Seaborn has six default palettes including deep, muted, pastel, bright, dark, and colorblind. Here are examples of how the different palettes look with a displot().

4. Displaying Palettes

Seaborn offers several convenience functions for working with palettes. The palplot() function display color swatches in a Jupyter notebook. In order to retrieve the current palette, you can use the color palette function. This short example shows the exact colors included in the default palettes and how to use each of these functions.

5. Defining Custom Palettes

There are three main types of color palettes. Circular color palettes are used for categorical data that is not ordered. Sequential palettes are useful when the data has a consistent range from high to low values. A diverging color palette is best used when both the high and the low values are interesting. Seaborn allows us to create each of these types of palettes in multiple manners. Each example on this slide shows a different automatically created palette of 12 different colors.

6. Let's practice!

Now that we have walked through creating and using some palettes in Seaborn, we can now apply these concepts to some more examples.