Sam B.
Sam B.

Reputation: 3043

pandas plot ylabels to the right or negative values from right to left

I'm plotting a graph with pandas like so

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)

It returns this graph

enter image description here

This makes it a bit more harder to correlate the name with a column unlike positive values

enter image description here

The fix would be to either move the ylabels to the right or have the xvalues for the negative values move from right to left

Upvotes: 0

Views: 386

Answers (2)

JARS
JARS

Reputation: 1129

With matplotlib axes' tick_right():

ax = frm.plot(x='country', y='Delivery Quality', kind='barh', figsize=(10,5), legend=False, secondary_y='country')
ax.yaxis.tick_right()

Upvotes: 1

Gozy4
Gozy4

Reputation: 494

You can do something like this which will create a second label on the right side of the plot and hide the label on the left side.

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

Upvotes: 0

Related Questions