1

I'm sorry for asking this again because I know this has been asked several times before, and I've researched all of the other solutions that I can find on every other thread about it, but none of them work for me. No matter what I try, these xlabels still always come out horizontal and jumbled together. I don't know why mine is not working while others worked, but I suspect it has to do with the fact I have three subplots on the figure.

I have tried the following, and many other things as well:

ax1.set_xticklabels(rotation=30) <-- Nothing happens

axs[0].set_xticklabels(rotation=30) <-- Error

plt.xticks(rotation=45) <-- Nothing happens

Here is the code and the plots.

    customer_rev_df = pd.DataFrame(customer_rev, columns='Week Revenue Pieces Stops'.split())
    print(customer_rev_df.set_index('Week'))
    sns.set_style(style='whitegrid')
    fig, axs = plt.subplots(ncols=3, figsize=(16, 6))
    ax1 = sns.factorplot(x='Week', y='Revenue', data=customer_rev_df, ax=axs[0])
    ax2 = sns.factorplot(x='Week', y='Stops', data=customer_rev_df, ax=axs[1])
    ax3 = sns.factorplot(x='Week', y='Pieces', data=customer_rev_df, ax=axs[2])
    axs[0].set_ylabel('Revenue')
    axs[1].set_ylabel('Stops')
    axs[2].set_ylabel('Pieces')
    axs[0].set_title('Weekly Revenue')
    axs[1].set_title('Weekly Stops')
    axs[2].set_title('Weekly Pieces')
    plt.tight_layout()
    fig.show()

Example of my figure

I admit I'm still relatively new so go easy on me! Any help would appreciated. Thanks!

Emac
  • 1,098
  • 3
  • 18
  • 37

1 Answers1

5

Setting the xticklabels with .set_xticklabels() requires to actually specify the xticklabels, like ax.set_xticklabels([1,2,3,4], rotation=30).

If you already have a nice plot and don't want to change the ticklabels themselves, you can do the following:

plt.setp(ax.get_xticklabels(), rotation=30)

where ax is the axes for which you want to rotate the xticklabels.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    I wasted hours researching it and testing it and couldn't get it, you solved it just a couple minutes after I asked. You guys are amazing! Thank you! – Emac May 12 '17 at 17:19