How do you rotate axis text on Seaborn JointGrid?

Viewed 22

enter image description here

How do you rotate the text along the x-axis to avoid unreadable text like the one above?

plt.figure(figsize = (10,8))   
g = sns.JointGrid(x='u',y='t',data = tdata)
g.plot(sns.scatterplot, sns.histplot)
plt.show()

And plt.figure also can't work on JoinGrid,

1 Answers

You can get axes with g.ax_joint and from here your can set you axis attributes.

Solution 1: tick_params()

plt.figure(figsize=(10, 8))
g = sns.JointGrid(x="u", y="t", data=tdata)
g.plot(sns.scatterplot, sns.histplot)
g.ax_joint.tick_params(axis="x", rotation=90)
plt.show()

Solution 2: set_xticklabels()

plt.figure(figsize=(10, 8))
g = sns.JointGrid(x="u", y="t", data=tdata)
g.plot(sns.scatterplot, sns.histplot)
g.ax_joint.set_xticklabels(g.ax_joint.get_xticks(), rotation=45)
plt.show()

Solution 3: get_xticklabels()

With this you can iterate over all the ticks and change their rotation individually.

plt.figure(figsize=(10, 8))
g = sns.JointGrid(x="u", y="t", data=tdata)
g.plot(sns.scatterplot, sns.histplot)
for tick in g.ax_joint.get_xticklabels():
    tick.set_rotation(30)
plt.show()

PS:

xticklabels can be different for precision based on the precision value return by each function.

Related