开始使用免费开始使用

您的第一张图!

让我们把您目前学到的内容串起来,绘制您的第一张时间序列图。您将先打好基础:对数据生成一张时间序列图,并给坐标轴加上标签,这能让图形更易读、也更便于目标读者理解。

matplotlib 是 Python 中使用最广泛的绘图库,非常适合完成这项工作。好消息是,pandas 库在 Series 和 DataFrame 对象上实现了 .plot() 方法,它是对 matplotlib.pyplot.plot() 的封装,使绘图更为便捷。

本练习是课程的一部分

用 Python 可视化时间序列数据

查看课程

练习说明

  • 'date' 列设置为 DataFrame 的索引。
  • 使用 discoveries DataFrame,以"blue"线图绘制其中的时间序列,并将返回的坐标轴对象赋给 ax
  • 将图中的 x 轴标签设为:'Date'
  • 将图中的 y 轴标签设为:'Number of great discoveries'

交互式实操练习

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

# Set the date column as the index of your DataFrame discoveries
discoveries = ____

# Plot the time series in your DataFrame
ax = discoveries.____(____=____)

# Specify the x-axis label in your plot
____('Date')

# Specify the y-axis label in your plot
____('Number of great discoveries')

# Show plot
plt.show()
编辑并运行代码