开始使用免费开始使用

玩转样式

帮帮 Laura 警官尝试几种不同的样式选项。更改绘图样式可以快速改变整张图的外观,而无需逐一修改颜色或线型。一些常用样式包括:

  • 'fivethirtyeight' —— 基于知名网站的配色方案
  • 'grayscale' —— 适合在没有彩色打印机时使用!
  • 'seaborn-v0_8' —— 基于另一款 Python 可视化库
  • 'classic' —— Matplotlib 的默认配色方案

本练习是课程的一部分

Python 数据科学入门

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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()
编辑并运行代码