向 Axes 对象添加数据
向图形添加数据是通过调用 Axes 对象的方法来完成的。在本练习中,您将使用 plot 方法添加两座美国城市(华盛顿州的西雅图和德克萨斯州的奥斯汀)的降雨量数据。
这些数据已加载到内存中的两个 pandas DataFrame 对象中:seattle_weather 存储西雅图的气象信息,austin_weather 存储奥斯汀的气象信息。每个 DataFrame 都有一个 "MONTH" 列,存放月份的三字母名称。它们还各自包含一个名为 "MLY-PRCP-NORMAL" 的列,存放 10 年期间各月份的平均降雨量。
在本练习中,您将创建一个可视化,用于比较这两座城市的降雨情况。
本练习是课程的一部分
Matplotlib 数据可视化入门
练习说明
- 将
matplotlib.pyplot子模块以plt的别名导入。 - 调用
plt.subplots创建一个 Figure 和一个 Axes 对象。 - 调用 Axes 的
plot方法,添加seattle_weatherDataFrame 的数据。 - 以相同方式添加
austin_weatherDataFrame 的数据,并调用plt.show显示结果。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the matplotlib.pyplot submodule and name it plt
____
# Create a Figure and an Axes with plt.subplots
fig, ax = ____
# Plot MLY-PRCP-NORMAL from seattle_weather against the MONTH
ax.____(seattle_weather["MONTH"], ____)
# Plot MLY-PRCP-NORMAL from austin_weather against MONTH
ax.____(____, ____)
# Call the show function
____