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)
Advertisement
Answer
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()
Complete Code
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()