-1

enter image description hereI am trying to do rotation for my shared x axis xticks but the rotation works for some of the subplots and not for others. Could anyone point out my mistake

plt.rcParams["figure.figsize"] = [15.00, 7]
plt.rcParams["figure.autolayout"] = True
plt.tight_layout()

fig,ax = plt.subplots(3,2, sharex =True)
plt.xticks(rotation=45);

#fig.subplots_adjust(hspace=0.4, wspace=0.4)

sns.lineplot(ax=ax[0,0],x='YEAR',y ='GDP',data=data1, label ='GDP')
ax[0,0].title.set_text('GDP with DATE')
plt.xticks(rotation=45)

sns.lineplot(ax=ax[0,1],x='YEAR',y='mediansoldprice',data=data1)
ax[0,1].title.set_text('mediansoldprice with DATE')
plt.xticks(rotation=45)

sns.lineplot(ax=ax[1,0],x='YEAR',y='interestrates',data=data1,label ='interestrates')
plt.xticks(rotation=45)
sns.lineplot(ax=ax[1,1],x='YEAR',y='30yr_fixed_mortigage',data=data1, 
label='30yr_fixed_mortigage')
plt.xticks(rotation=45)
sns.lineplot(ax=ax[2,0],x='YEAR',y='homeindex',data=data1,label ='homeindex')
plt.xticks(rotation=45)
plt.show()
Malu soma
  • 7
  • 2

1 Answers1

1

Hard to tell exactly what your problem is without test data and a description or image of the specific plot failure, but the issue is mostly likely that you are calling plt.xticks(rotation=45) rather than setting the rotation for each subplot. You can use matplotlib methods to set the rotation, and there are several ways to do that as described in this answer. Here is a minimum example that you could modify for your plot:

import matplotlib.pyplot as plt
import seaborn as sns

fig, ax = plt.subplots(2,2)

x = [1,2,3,4,5]
y = [i**2 for i in x]

sns.lineplot(ax=ax[0,0], x = x, y = y)
ax[0,0].tick_params("x",labelrotation=45)

sns.lineplot(ax=ax[0,1], x = x, y = y)
ax[0,1].tick_params("x",labelrotation=45)

sns.lineplot(ax=ax[1,0], x = x, y = y)
ax[1,0].tick_params("x",labelrotation=45)

sns.lineplot(ax=ax[1,1], x = x, y = y)
ax[1,1].tick_params("x",labelrotation=45)

plt.tight_layout()
plt.show()

enter image description here

astroChance
  • 337
  • 1
  • 10