我的数据看起来像
print(core_df2)
dispatch_patch
date
2019-11-13 18:28:00 50
2019-11-13 18:29:00 450
2019-11-13 18:30:00 825
2019-11-13 18:31:00 1450
2019-11-13 18:32:00 1725
... ...
2019-11-13 19:26:00 4850
2019-11-13 19:27:00 4875
2019-11-13 19:28:00 5175
2019-11-13 19:29:00 4314
2019-11-13 19:30:00 6
[63 rows x 1 columns]
我正在尝试制作条形图,但遇到问题。
如果我像这样画条形图
core_df2.plot.bar() #I can see the plot
但是我像下面这样使用,它显示错误消息。
37 plt.figure(figsize=(17,12))
---> 38 plt.bar(core_df2)
39
TypeError: bar() missing 1 required positional argument: 'height'
还有,如果我使用
plt.figure(figsize=(17,12))
plt.plot(core_df2)
#I can see the plot.
似乎 plt.bar 无法获取时间索引作为 x 轴值。
你知道我该如何解决这个问题吗?
谢谢
最佳答案
您可以传递dataframe.index,然后传递列名称。
plt.bar(core_df2.index, core_df2['dispatch_patch'])
关于python - plt.bar 错误,类型错误 : bar() missing 1 required positional argument: 'height' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58968716/