Get startedGet started for free

Using a custom categorical palette

When you have a line chart with lots of categories choosing your palette carefully is essential. Often default palettes have very similar hues, that are hard to differentiate when spread over the small surface of a line. ColorBrewer palettes are built with this in mind and keep the colors as distinct as possible.

In this exercise, you will make a line plot of the O3 values over the year of 2013 for all the cities where the color of each line is encoded by city. You will use the ColorBrewer palette 'Set2' to improve upon the default color scheme.

This exercise is part of the course

Improving Your Data Visualizations in Python

View Course

Exercise instructions

  • Query data to January of 2013.
  • Encode the color of the lines as the city.
  • Change the palette to the 'Set2' ColorBrewer palette.

Hands-on interactive exercise

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

# Filter our data to Jan 2013
pollution_jan13 = pollution.query('year  ==  ____ & month  ==  ____')

# Color lines by the city and use custom ColorBrewer palette
sns.lineplot(x = "day", 
             y = "CO", 
             ____ = "____",
             ____ = "____", 
             linewidth = 3,
             data = pollution_jan13)
plt.show()
Edit and Run Code