0

I have a figure with multiple subplots. For some reason, the set_xticklabels method does not work for these subplots.

Here is the code am using:

n_rows=len(customers)
fig,ax = plt.subplots(n_rows,2, figsize=(18,72))
fig.suptitle('Mytitile',fontsize=16)
fig.subplots_adjust(hspace=0.4, wspace=0.4)
#fig.tight_layout()
fig.subplots_adjust(top=0.97)
sns.set_style("ticks")
for i,client in enumerate(customers):
    df = df1[df1['Client'] == client]
    sns.lineplot(data = df, x='date', y='income',ax=ax[i,0]).set_title(client)
    ax[i,0].yaxis.set_major_formatter(ticker.EngFormatter())
    sns.lineplot(data = df, x='date', y='cost',ax=ax[i,1]).set_title(client)
    ax[i,1].yaxis.set_major_formatter(ticker.EngFormatter())

I was hoping

ax[i,0].set_xticklabels(ax[i,0].get_xticklabels(), rotation=45,horizontalalignment='right')

would do the trick, but it isnt. (It simply vanishes the labels altogether) Any ideas why and how can i fix it?

William Miller
  • 9,839
  • 3
  • 25
  • 46
asimo
  • 2,340
  • 11
  • 29

1 Answers1

3

It would be simpler to use ax.tick_params to set the rotation,

ax[i, 0].tick_params('x', labelrotation=45)

'x', 'y', or 'both' can be specified for the (optional) first argument (default is 'both') and will control to which axes the label rotation is applied.

Perhaps you should try that instead

William Miller
  • 9,839
  • 3
  • 25
  • 46