matplotlib中缺少标签 - 条形图

时间:2017-07-19 10:08:52

标签: python matplotlib

当我绘制水平条形图时,当我手动设置y轴时,我看到x轴和y轴都缺少一个图例。

bar_locations = np.arange(6)
ax.barh(bar_locations, data ,alpha=.5)
bar_locations = np.arange(6)
# data = [55, 22, 40, 56, 109, 180]
# labels = ['others', u'Belts', u'Apparel & Accessories > Jewelry', u'Jewelry', u'Fragrances', u'Watches']
ax.barh(bar_locations, data ,alpha=.5)
ax.set_yticklabels(labels)
fig.tight_layout()

enter image description here

1 个答案:

答案 0 :(得分:4)

您还需要设置刻度线位置

ax.set_yticks(bar_locations)
ax.set_yticklabels(labels)