CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Improving Your Data Visualizations in Python

Afficher le cours

Instructions

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

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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()
Modifier et exécuter le code