Pandas 绘图问题

Pandas plotting issue

我有以下数据框:

Price,Volume
6550,18
6551,5
6552,2
6553,13
......
......
......
7001,3
7002,21

我想要一根轴上的价格和另一根轴上的成交量。由于这是一个 pandas 数据框,我觉得我可以按如下方式绘制它:

df.plot(kind='bar')
plt.show()

但是它是沿着同一轴绘制两列。我希望每一列都在一个单独的轴上。我尝试了以下不起作用的方法:

df.plot(kind='bar', xticks=df['Price'], yticks=df['Volume'])

任何关于我做错的建议都将不胜感激。

当您使用 df.plot(kind='bar') 绘图时,它将使用索引作为 x 轴,然后将 DataFrame 中的所有列绘制为 y 值。

要解决这个问题,you can choose x and y values to be used,例如:

df.plot(x='Price', y='Volume', kind='bar')

有关使用 pandas 绘图的更多示例,请参阅 here

通过标签指定您想要的 x 和 y:

df.plot(x='Price', y='Volume', kind='bar')

这里是完整的文档:

http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.plot.html