Search code examples
pythonmatplotlibsubplotxticks

How do i apply a xticks rotation on all my subplots?


I am kind of stuck with this, I searched on google for an answer but I can not find it.

I would like to turn my xticks 45 degrees of my subplot. I know how to do it for a normal plot:

plt.xticks(rotation = 45)

But when I put this in my plot script nothing happens. I would really like to know how I can apply this to all my subplots at the same time.

This is my code:

plt.figure()

fig, axs = plt.subplots(1, 3, sharey=True, tight_layout=True)
axs[0].set_title("Classic")
axs[1].set_title("Theta")
axs[2].set_title("Vector")


axs[0].plot(df.time,df.classic, label = 'Classic', color = 'blue')
axs[1].plot(df.time,df.theta, label = 'Theta', color = 'green')
axs[2].plot(df.time,df.vector, label = 'Vector', color = 'red')

plt.xticks(rotation = 45)
plt.suptitle('Core computations',fontsize=20)
plt.legend()
plt.show()

Solution

  • Try with setp() function to set a certain parameter, in this case rotation:

    ax = plt.gca()
    plt.setp(ax.get_xticklabels(), rotation=45)