我想弄清楚如何更改图表x轴上日期的旋转。见下图。我有一些如何做的例子,但由于我有双y轴,它们不能很好地匹配。你能帮忙改变日期的轮换吗?
这是我的代码:
fig, ax1 = plt.subplots()
fig = plt.figure(figsize=(8,6))
t = df['date']
s1 = df['msft']
ax1.plot(t, s1, 'b-')
ax1.set_xlabel('Dates')
ax1.legend(loc=0)
ax1.grid()
# Make the y-axis label, ticks and tick labels match the line color.
ax1.set_ylabel('Price', color='b')
ax1.tick_params('y', colors='b')
ax2 = ax1.twinx()
s2 = df['amzn']
ax2.plot(t, s2, 'r-')
ax2.set_ylabel('amzn', color='r')
ax2.tick_params('date', colors='r')
ax2.legend(loc=0)
fig.tight_layout()
plt.show()