matplotlib中缺少标签-条形图

Har*_*nan 3 python matplotlib

当绘制水平条形图时,当我手动设置yaxis时,我看到在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()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Imp*_*est 5

您还需要设置刻度位置

ax.set_yticks(bar_locations)
ax.set_yticklabels(labels)
Run Code Online (Sandbox Code Playgroud)