【发布时间】:2019-10-31 05:35:44
【问题描述】:
我正在尝试使用 pandas.plot(kind='barh') 创建一个绘图,但在绘图中间(从 X 轴角度看是中间)获得居中的框。
使用此代码:
ax = df.May2019.T.plot(kind='barh', subplots = False, stacked=True,
figsize=(12,8), title = 'Number of customers per revenue slice',
width=0.99)
vals = ax.get_yticks()
ax.set_yticklabels(['60%-80%', '40%-60%', '20%-40%', '0%-20%'])
ax.set_ylabel('Top x% Revenue')
ax.set_xlabel('Number of customers in revenue band')
我希望将所有框居中放置在图表中间。我知道 X 轴会变得不那么有意义,但我正在寻找图像的价值。
我的 pd.Series 看起来像这样
0.8 75
0.6 26
0.4 10
0.2 3
Name: May2019, dtype: int64
关于我应该查看/更改什么的任何建议?
【问题讨论】:
-
您可以将
ax.set_xlim(-ax.get_xlim()[1], None)设置为轴中间的0。你是这个意思吗?如果不是,请多花点时间描述问题。 -
另外,请提供一个代码,可以简单地复制粘贴并执行以获得发布的数字。以可复制的格式发布数据框
标签: python pandas matplotlib charts