Get startedGet started for free

Adjusting your palette according to context

You've been asked to make a figure for your company's website. The website has a slick black theme, and it would be pretty jarring if your plot were white. To make your plot match the company aesthetic, you can swap the background to a black one with plt.style.use("dark_background").

The figure you've been asked to make plots O3 values during October 2015 for various cities (provided as oct_2015_o3). You will plot this as a heatmap with the color of each cell encoding how many standard deviations from the overall average O3 value the measurement falls. Due to the website's dark background, you will want to adjust your color palette to encode null value (or 0 standard deviations from the mean) as dark rather than the default white.

This exercise is part of the course

Improving Your Data Visualizations in Python

View Course

Exercise instructions

  • Set the theme of the plot to be dark with plt.style.use().

    • You can see the available themes for plt.style.use() by running the line plt.style.available; look for the one that will make your background dark.
  • Modify the custom palette to be 'dark' for the center value instead of the default white.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Dark plot background
plt.style.use("____")

# Modify palette for dark background
color_palette = sns.diverging_palette(250, 0,
                                      ____ = '____',
                                      as_cmap = True)

# Pass palette to plot and set center
sns.heatmap(oct_2015_o3,
            cmap = color_palette,
            center = 0)
plt.yticks(rotation = 0)
plt.show()
Edit and Run Code