Aan de slagGa gratis aan de slag

Playing with styles

Help Sergeant Laura try out a few different style options. Changing the plotting style is a fast way to change the entire look of your plot without having to update individual colors or line styles. Some popular styles include:

  • 'fivethirtyeight' - Based on the color scheme of the popular website
  • 'grayscale' - Great for when you don't have a color printer!
  • 'seaborn-v0_8' - Based on another Python visualization library
  • 'classic' - The default color scheme for Matplotlib

Deze oefening maakt deel uit van de cursus

Introduction to Data Science in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Change the style to fivethirtyeight
plt.____.____(____)

# Plot lines
plt.plot(data["Year"], data["Phoenix Police Dept"], label="Phoenix")
plt.plot(data["Year"], data["Los Angeles Police Dept"], label="Los Angeles")
plt.plot(data["Year"], data["Philadelphia Police Dept"], label="Philadelphia")

# Add a legend
plt.legend()

# Display the plot
plt.show()
Code bewerken en uitvoeren