如何使用matplotlib.pyplot.barh更改钢筋位置

时间:2019-01-10 18:55:46

标签: python-3.x matplotlib

我正在使用matplotlib.pyplot.barh绘制水平条形图,并想移动条形图的位置。我没有找到任何支持这一点的论点。有人遇到同样的问题吗?

ax1.set_title('Number of Accounts', size=12)
ax1.invert_yaxis()
ax1.invert_xaxis()
ax1.barh(c['Customer Group'], c['n_accts'],color='#f4be92')

现在1的小节在0到1之间,而2的小节在1和2之间。是否可以将小节移动到其相应编号所在的位置?

enter image description here

1 个答案:

答案 0 :(得分:1)

您应该使用居中对齐。为此,您可以将传递layoutSubviews()用作align='center'的参数。因此,只需使用

ax.barh

它将使条形图在y轴上居中。在此处查看docs