数据框绘制直方图如何更改标签?

3

我有一个名为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。我想让它们成为数据帧中类型列中的字符串。我在寻找如何自定义直方图的文档时遇到了困难,除了改变条的颜色之外。

1个回答

2
df.plot(x='type', y='success', kind='bar')
plt.xticks(rotation=25)

enter image description here

我通过查看文档字符串找到了这个:

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 值的错误。 - Kevin Thompson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接