2017-07-19 142 views
1

当我绘制水平条形图时,当我手动设置yaxis(如下图)时,我看到x轴和y轴都缺少一个图例。在matplotlib中缺失标签 - 条形图

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

回答

3

您需要设置刻度位置以及

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

很酷...在x轴标签仍下落不明。任何想法为什么? –

+0

代码中没有** x **标签的标签?!你可以使用'ax.set_xlabel(“label”)来设置' – ImportanceOfBeingErnest

+0

xaxis是根据数据自动绘制的吗? #data = [55,22,40,56,109,180] –