如何在 python 的 matplot 中设置 x 轴的值?

How do I set up the values for the x axis in matplot in python?

plt.figure(figsize=(15,5))
plt.plot(data['Unemployment Rate'])
plt.axis([1948,2017,0,15])
plt.show()

这些代码返回了一个空图。

table 包含 2 列,data['Year'] 和 data['Unemployment Rate']。

年份在 1948 年到 2017 年之间。

我想要完成的是生成失业率图表,并使用数据['Year']中的值作为 x 轴的值。

如果你想绘制 yx,你需要通知 matplotlib 这样做。

plt.plot(x,y)

如果您只调用 plt.plot(y),matplotlib 将不知道您要针对 x 数据绘图。相反,它需要数字 0,1,...N-1 来绘制。