【发布时间】:2014-12-06 01:38:14
【问题描述】:
我发现在使用 twinx 创建第二个轴后,我无法让轴自动缩放以在第一个轴上工作。这是预期的吗?
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x**2
y2 = -1 *y1
fig, axL = plt.subplots() # Make Left Axes
axR = axL.twinx() # Make Left Axes
axL.plot(x, y1, 'g-') # Plot on Left
axL.grid()
axL.autoscale(enable=True, axis=u'both', tight=False)
plt.show()
# Do some stuff then later plot on axR
当我运行上面的代码时,它会在左侧轴(0 到 5)上正确地在 y 方向上自动缩放,但将 X 轴刻度更改为 +/- 0.06 而不是正确的 0 到 10。但是,一旦 axR不再是空白,并且在 axR 上绘制了一些东西,它的行为与我预期的一样。
这只是一个例子,因为我在更复杂的 PyQT4 GUI 中第一次遇到这个问题,它允许用户创建多个子图和左/右组合。由于用户是手动控制情节创建顺序的人,因此上述情况可能会出现。
有没有办法让自动缩放与空白的 twinx 右轴一起工作。还是只需要手动设置 Xlimit?
仅供参考,我使用 Python 3.4 作为 Anaconda v2.0.1 的一部分和 Matplotlib v1.3.1
谢谢。
【问题讨论】:
标签: python matplotlib