问题描述
我想绘制以下数据集(列maxnet
).
如果我使用Pandas DataFrame在Python中执行以下操作:
If I do the following in Python using Pandas DataFrame:
df['maxnet'].hist(bins=10,range=(5,11), grid=False, alpha=0.3, histtype="stepfilled")
我得到下图:
如您所见,我没有在每个条形下居中放置x轴值.我希望将x值(6、7、8、9、10)居中于条形下方.我该怎么办?
As you can see, I don't have the x-axis values centered under each bar. I want the x-values (6, 7, 8, 9, 10) to be centered under the bar. How can I do that?
此外,如果我想更改(Dec6,Dec7,Dec8,Dec8,Dec9,Dec10)的x轴标签,但仍在每个小节的正下方,我该怎么做?
Also, if I want to change the x-axis label for (Dec6, Dec7, Dec8, Dec9, Dec10), still centered under each bar, how can I do that?
推荐答案
根据BrenBarn的建议,我能够解决我的问题.这是我的解决方案:
From the suggestion of BrenBarn, I was able solve my problem. Here's my solution:
bar = pd.DataFrame(maxdf['maxnet'].value_counts())bar = bar.sort()bar.plot(kind='bar')
bar = pd.DataFrame(maxdf['maxnet'].value_counts())bar = bar.sort()bar.plot(kind='bar')
这篇关于Python:Pandas以居中的x值绘制直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!