0

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

As per this question, I believe this can be done with plt.setp().

# Create subplots
fig, ax = plt.subplots(2, 2, figsize=(10,5), sharex=True, sharey=True)
# Try to rotate the xticks of all axes
plt.setp(plt.xticks()[1], rotation=45) # Close attempt
# Show
plt.show()

close

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Arturo Sbr
  • 5,567
  • 4
  • 38
  • 76

1 Answers1

5

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

butterflyknife
  • 1,438
  • 8
  • 17