gpt4 book ai didi

python - pandas.DataFrame.plot(kind ="bar")的更多绘图选项

转载 作者:行者123 更新时间:2023-12-01 05:13:07 24 4
gpt4 key购买 nike

pandas.DataFrame.plot(kind='bar') 方法很方便,因为它可以绘制按数据框的行和列分组并适当着色的条形图。例如:

timeDf.plot(kind='bar', legend=False)

产生

enter image description here

对于以下数据框:

enter image description here

但是如果我希望情节有,例如<​​/p>

  • 对数 y 轴
  • y 轴和 x 轴标签

该方法本身似乎没有相应的选项?对定制的支持是否如此有限,或者我错过了什么?

我犹豫是否在 matplotlib 中重建这个绘图函数,因为我认为它很费力。

最佳答案

set_scaleset_xticklabels 用于这些:

df=pd.DataFrame(np.random.random((6,6)))
ax=df.plot(kind='bar')
ax.yaxis.set_scale('log')
ax.set_xticklabels(['a','b','c','d','e','f'])

enter image description here

如果您希望刻度线均匀分布,您应该这样做:

ax.set_yscale("log", nonposy='clip') #nonposy is required, otherwise the bar disappears.
ax.set_ylim((0.1, 100)) #remember to rest the limit.

enter image description here

matplotlib 1.3 起,set_scale 方法已弃用,并替换为 _set_scale

关于python - pandas.DataFrame.plot(kind ="bar")的更多绘图选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23791849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com