大熊猫将ylabel绘制在右侧或从右到左的负值

时间:2018-07-26 09:26:13

标签: python pandas matplotlib

我正在用大熊猫绘制图

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)

它返回此图

enter image description here

与正值不同,这使得将名称与列相关起来更加困难

enter image description here

解决方法是将ylabel向右移动,或者使负值的xvalue从右向左移动

2 个答案:

答案 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'])