简体   繁体   中英

Rotate x tick labels using subplots

As the title describes, I am using the subplots method to make bar charts. Everything works well but I can't figure out how to rotate the x tick labels. My graphing code is:

f, axarr = plt.subplots(2, sharex=True)

axarr[0].set_xticklabels(file2_temp)
axarr[0].xaxis.set_ticks(y)
axarr[0].bar(np.arange(len(file_temp)), stddev_temp, align='center', alpha=0.4)


axarr[1].bar(np.arange(len(file_RH)), stddev_RH, align='center', alpha=0.4)
axarr[1].tick_params(axis='x', pad=30)
plt.show()

Where file2_temp and RH are lists and stddev_temp and RH are my data.

Any help would be great. Thanks!

You can rotate ticks using setp.

Here's an example modified from your your post:

import matplotlib.pyplot as plt
from numpy.random import rand
import numpy as np

f, axarr = plt.subplots(2, sharex=True)

axarr[0].bar(np.arange(1,11), rand(10), align='center', alpha=0.4)
axarr[1].bar(np.arange(1,11), rand(10), align='center', alpha=0.4)

axarr[1].tick_params(axis='x', pad=30)

plt.setp(plt.xticks()[1], rotation=45)

plt.show()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM