python - plt.bar 错误,类型错误 : bar() missing 1 required positional argument: 'height'

标签 python dataframe plot

我的数据看起来像

    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/

相关文章:

r - 如何根据R中其他数据帧中的信息创建矩阵?

python - 如何获取包含与索引对应的特定值的列列表作为 Pandas 数据框中的新列?

python - 更改 df 的格式并删除不需要的字符

r - X 轴数字有小数

r - R 中具有叠加标准差曲线的多重直方图

python : How to find Accuracy Result in SVM Text Classifier Algorithm for Multilabel Class

python - django 无法打开数据库文件

python - 如何在 python 中获取驱动器的名称

python - 如何继承类的方法并让它们访问python中的自身成员变量

Python优化算法调整线越过尽可能多的点