Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在添加另一个yaxis时旋转xlabel?_Python_Matplotlib - Fatal编程技术网

Python 如何在添加另一个yaxis时旋转xlabel?

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

出于某种原因,在我向绘图中添加第二个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.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()
屈服


就是这样!我感谢你的帮助