Python 如何在添加另一个yaxis时旋转xlabel?
出于某种原因,在我向绘图中添加第二个y轴之后Python 如何在添加另一个yaxis时旋转xlabel?,python,matplotlib,Python,Matplotlib,出于某种原因,在我向绘图中添加第二个y轴之后 fig.plt.figure() ax = plt.Axes(fig) fig.add_axes(ax) ax2 = ax.twinx() fig.add_axes(ax2) Xticklabel不再旋转 fig.autofmt_xdate(rotation = num) 有人知道为什么会这样吗 我可以注释掉最后两行: #ax2 = ax.twinx() #fig.add_axes(ax2) 它将旋转Xticklabel。将fig.autofm
fig.plt.figure()
ax = plt.Axes(fig)
fig.add_axes(ax)
ax2 = ax.twinx()
fig.add_axes(ax2)
Xticklabel不再旋转
fig.autofmt_xdate(rotation = num)
有人知道为什么会这样吗
我可以注释掉最后两行:
#ax2 = ax.twinx()
#fig.add_axes(ax2)
它将旋转Xticklabel。将
fig.autofmt\u xdate(rotation=num)
放在定义ax
的语句之后,但在调用ax.twinx()之前,并且:
import matplotlib.pyplot as plt
import matplotlib.dates as md
import datetime as dt
import numpy as np
np.random.seed(0)
t=md.drange(dt.datetime(2009,10,1),
dt.datetime(2010,1,15),
dt.timedelta(days=1))
n=len(t)
x1 = np.cumsum(np.random.random(n) - 0.5) * 40000
x2 = np.cumsum(np.random.random(n) - 0.5) * 0.002
fig = plt.figure()
# fig.autofmt_xdate(rotation=25) # does not work
ax1 = fig.add_subplot(1,1,1)
fig.autofmt_xdate(rotation=25) # works
ax2 = ax1.twinx()
# fig.autofmt_xdate(rotation=25) # does not work
ax1.plot_date(t, x1, 'r-')
ax2.plot_date(t, x2, 'g-')
plt.show()
屈服
就是这样!我感谢你的帮助