How can I make the horizontal seaborn barplot right aligned / mirrored
import matplotlib.pyplot as plt
import seaborn as sns
x = ['x1', 'x2', 'x3']
y = [4, 6, 3]
sns.barplot(x=y, y=x, orient='h')
plt.show()
The default horizontal barplot looks like this

I want to have something like this (with proper xticks)

In order to invert the x axis, you can use:
ax.invert_xaxis()
Then, in order to move the labels to the right, you can use:
plt.tick_params(axis = 'y', left = False, right = True, labelleft = False, labelright = True)
or, shorter:
ax.yaxis.tight_right()
import matplotlib.pyplot as plt
import seaborn as sns
x = ['x1', 'x2', 'x3']
y = [4, 6, 3]
ax = sns.barplot(x=y, y=x, orient='h')
ax.invert_xaxis()
ax.yaxis.tick_right()
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With