LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Improving Your Data Visualizations in Python

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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()
Code bearbeiten und ausführen