【问题标题】:dataframe.plot histogram change labeldataframe.plot 直方图更改标签
【发布时间】:2014-02-20 04:23:15
【问题描述】:

我有一个名为 df 的数据框,看起来像这样

   success        type
1  0.197642  Technique 1
2  0.177575  Technique 2
0  0.018519  Technique 3

然后我绘制它: df.success.plot(kind="bar")

但是条形图的标签是 1,2,0。我希望它们成为我的数据框类型列中的字符串。我无法找到有关如何自定义直方图的文档,而不仅仅是更改条形的颜色。

【问题讨论】:

    标签: python matplotlib pandas


    【解决方案1】:
    df.plot(x='type', y='success', kind='bar')
    plt.xticks(rotation=25)
    

    我通过查看the docstring 找到了这个:

    In [11]: df.plot?
    ...
    Parameters
    ----------
    frame : DataFrame
    x : label or position, default None
    y : label or position, default None
        Allows plotting of one column versus another
    

    【讨论】:

    • 我明白了。所以看起来使用 df.success.plot 是问题的一部分,因为当我使用 y=success 时,我得到一个关于多个 y 值的错误。
    猜你喜欢
    • 2020-12-14
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 2019-11-18
    • 2021-04-18
    • 2022-01-20
    • 1970-01-01
    相关资源
    最近更新 更多