1. Learn
  2. /
  3. 课程
  4. /
  5. Matplotlib 数据可视化入门

Connected

道练习

自定义坐标轴标签并添加标题

要自定义坐标轴标签,需要使用 Axes 对象的 set_xlabel 和 set_ylabel 方法。添加标题使用 set_title 方法。

在本练习中,您将自定义坐标轴标签的内容,并为图表添加标题。

与之前一样,数据已作为 pandas DataFrame 对象加载到内存中:seattle_weather 和 austin_weather。它们各自包含 "MONTH" 列和 "MLY-PRCP-NORMAL" 列。示例代码前两行已将这些数据相互作图。

此外,名为 fig 的 Figure 对象和名为 ax 的 Axes 对象已经为您创建好了。

说明

100 XP
  • 使用 set_xlabel 方法添加标签:"Time (months)"。
  • 使用 set_ylabel 方法添加标签:"Precipitation (inches)"。
  • 使用 set_title 方法添加标题:"Weather patterns in Austin and Seattle"。