Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change rotation of xticks in matplotlib?

I want to change the rotation of the xticks, but I am ending with x AND yticks rotated. How can I rotate just the xticks?

Here is my code:

# Plot mit Sidestepped 0/1

sns.set(style="darkgrid")

fig, ax = plt.subplots(1,2, figsize=(14,5))

for i in range(len(ax)):
    ax[i].tick_params(labelsize=15)
    ax[i].set_xlabel('label', fontsize=17, position=(.5,20))
    ax[i].set_ylabel('label', fontsize=17)

sns.countplot(x="page_name", hue="successful", data=mainDf, ax=ax[0]); 
sns.countplot(x="industry", hue="successful", data=mainDf, ax=ax[1]);

fig.suptitle('Categorical Features Count', position=(.5,1.1), fontsize=20)
ax[0].set_title('Type by Industry', fontsize=18)
ax[0].set_xlabel('Industry')
ax[0].tick_params(rotation=50)
ax[1].set_title('Success by Industry',  fontsize=18)
ax[1].set_xlabel('Industry')
fig.tight_layout()

fig.show()

And here is what I get (x BUT unfortunately also yticks rotated! Look at just the left plot at ax[0]! I want to rotate just the xticks of the left plot!):

plot

like image 804
ZelelB Avatar asked Dec 14 '18 14:12

ZelelB


1 Answers

You can use the axis argument for tick_params to specify the rotation for a specific axis:

ax[0].tick_params(axis="x", rotation=50)
like image 200
DavidG Avatar answered Oct 28 '22 23:10

DavidG