Colors in Seaborn

Intermediate Data Visualization with Seaborn

Chris Moffitt

Instructor

Defining a color for a plot

  • Seaborn supports assigning colors to plots using matplotlib color codes
sns.set(color_codes=True)
sns.displot(df['Tuition'], color='g')

Green Displot

Intermediate Data Visualization with Seaborn

Palettes

  • Seaborn uses the set_palette() function to define a palette
palettes = ['deep', 'muted', 'pastel', 'bright', 'dark','colorblind']
for p in palettes:
    sns.set_palette(p)
    sns.displot(df['Tuition'])

Palette Comparison

Intermediate Data Visualization with Seaborn

Displaying Palettes

  • sns.palplot() function displays a palette
  • sns.color_palette() returns the current palette
palettes = ['deep', 'muted', 'pastel', 'bright','dark','colorblind']
for p in palettes:
    sns.set_palette(p)
    sns.palplot(sns.color_palette())
    plt.show()

Palette colors

Intermediate Data Visualization with Seaborn

Defining Custom Palettes

  • Circular colors = when the data is not ordered
sns.palplot(sns.color_palette("Paired", 12))

Paired palette

  • Sequential colors = when the data has a consistent range from high to low
sns.palplot(sns.color_palette("Blues", 12))

Blues palette

  • Diverging colors = when both the low and high values are interesting
sns.palplot(sns.color_palette("BrBG", 12))

BrBg palette

Intermediate Data Visualization with Seaborn

Let's practice!

Intermediate Data Visualization with Seaborn

Preparing Video For Download...