【发布时间】:2019-05-05 17:28:35
【问题描述】:
我正在尝试共享 matplotlib 轴 在(例如 axsA)它们被 绘制(不仅仅是在它们被 created 之后)。与我的预期相反,在进行连接后,即使我执行 plt.draw() 和 plt.show(),轴也不会使用共享 xlim 重绘:
import matplotlib.pyplot as plt
# Share two subplot axes AFTER plotting
figA, axsA = plt.subplots(1, 2, sharex=False)
axsA[0].plot(range(0, 10), range(10))
axsA[1].plot(range(3, 13), range(10))
axsA[0].get_shared_x_axes().join(axsA[0], axsA[1])
figA.suptitle('Join after plotting: x-axes limits are not the same in the two axes.')
plt.draw()
plt.show()
只有在在绘图之前将它们加入到 Grouper 对象中时,我似乎才能实现共享轴:
# Share two subplot axes BEFORE plotting
figB, axsB = plt.subplots(1, 2, sharex=False)
axsB[0].get_shared_x_axes().join(axsB[0], axsB[1])
axsB[0].plot(range(0, 10), range(10))
axsB[1].plot(range(3, 13), range(10))
figB.suptitle('Join after creation, before plotting: x-axes limits are the same oin both axes.')
这是 matplotlib.pyplot 中的错误还是我的理解?
【问题讨论】:
-
标记为重复,因为链接的答案已经告诉您您可能想要自动缩放。
-
啊,谢谢。我忽略了另一个答案中的“你可能想要 ax.autoscale()”评论,不知道它的用途。
标签: python matplotlib