我正在用大熊猫绘制图
df9[(df9['Delivery Quality'] < 0) & (df9['year'] == 2016)][['country','Delivery Quality']].plot(x='country', y='Delivery Quality', kind='barh', figsize=(20,20), legend=False, secondary_y=False)
它返回此图
与正值不同,这使得将名称与列相关起来更加困难
解决方法是将ylabel向右移动,或者使负值的xvalue从右向左移动
答案 0 :(得分:1)
使用matplotlib轴的tick_right()
:
ax = frm.plot(x='country', y='Delivery Quality', kind='barh', figsize=(10,5), legend=False, secondary_y='country')
ax.yaxis.tick_right()
答案 1 :(得分:0)
您可以执行以下操作,在图的右侧创建第二个标签,并在左侧隐藏标签。
ax = df9[(df9['Delivery Quality'] < 0) & (df9['year'] == 2016)][['country','Delivery Quality']].plot(x='country', y='Delivery Quality', kind='barh', figsize=(20,20), legend=False, secondary_y=False)
ax2 = ax.twinx()
ax.set_yticks([])
ax2.set_yticks(df['country'])