【发布时间】:2018-12-31 14:07:14
【问题描述】:
这是我的数据:
a3=pd.DataFrame({'OfficeName':['a','b','c','d','e','f','g','h'],
'Ratio': [0.1,0.15,0.2,0.3,0.2,0.25,0.1,0.4]})
这是我绘制条形图的代码:
fig, ax = plt.subplots()
ind = np.arange(a3.loc[:,'OfficeName'].nunique()) # the x locations for the groups
width = 0.35 # the width of the bars
p1 = ax.bar(ind,a3.loc[:,'Ratio'],width)
ax.set_title('Ratio of refunds to purchases')
ax.set_xticklabels(a3.loc[:,'OfficeName'],ha='center')
#ax.set_xticklabels(['a','b','c','d','e','f','g','h'],ha='center')
ax.set_xlabel('x Group')
ax.set_ylabel('Ratio')
plt.show()
但是,在我的图表中,第一个 x 标签丢失了:
我认为这个问题与Matplotlib: Move x-axis tick labels one position to left 不一样,因为我什至不需要旋转 x 标签。
谁能解释为什么会发生这种情况以及如何解决它?
【问题讨论】:
-
切勿在未指定标签位置的情况下使用
ax.set_ticklabels,即ax.set_ticks。
标签: python pandas matplotlib label