Home > Software engineering >  Rotate xticks in subplots (xticklabels rotation)
Rotate xticks in subplots (xticklabels rotation)

Time:11-04

I have a figure with four subplots in it. I want to rotate the xticks of all suplots by 45 degrees.

As per close

CodePudding user response:

You can cycle through each of your subplots, set it to the current axes, and call plt.xticks() on each one.

fig, axes = plt.subplots(2, 2, figsize=(10,5), sharex=True, sharey=True)

for ax in axes.flatten():
    plt.sca(ax)
    plt.xticks(rotation = 45)

Result:

enter image description here

  • Related