2
我在下面写了一个简单的脚本来用matplotlib生成一个图。我想将x-tick频率从每月增加到每周并旋转标签。我不知道从哪里开始使用x轴频率。我的旋转线产生一个错误:TypeError: set_xticks() got an unexpected keyword argument 'rotation'
。对于旋转,我不希望使用plt.xticks(rotation=70)
,因为我最终可能会在多个子图中构建,其中一些应该有一个旋转的轴,一些不应该。Matplotlib中x轴标签的频率和旋转
import datetime
import matplotlib
import matplotlib.pyplot as plt
from datetime import date, datetime, timedelta
def date_increments(start, end, delta):
curr = start
while curr <= end:
yield curr
curr += delta
x_values = [[res] for res in date_increments(date(2014, 1, 1), date(2014, 12, 31), timedelta(days=1))]
print len(x_values)
y_values = [x**2 for x in range(len(x_values))]
print len(y_values)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x_values, y_values)
ax.set_xticks(rotation=70)
plt.show()