MulaiMulai sekarang secara gratis

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

Latihan ini adalah bagian dari kursus

Introduction to Data Science in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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()
Edit dan Jalankan Kode