【问题标题】:link axis between different plot (no subplots) using matplotlib使用 matplotlib 连接不同图(无子图)之间的轴
【发布时间】:2013-01-24 21:20:37
【问题描述】:

这是我的问题。我知道如果它们是同一图中的子图,则有一种简单的方法可以链接不同图的轴:

import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212, sharex=ax1)

但我想知道是否有办法在定义 2 个不同的图形时(我希望这些图形远离彼此所以我想我不能把它们放在同一个图中......)

非常感谢!

【问题讨论】:

标签: python matplotlib plot


【解决方案1】:

你只是做同样的事情,但使用不同的数字。

import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
fig2 = plt.figure()
ax2 = fig2.add_subplot(111, sharex=ax1)

【讨论】:

  • 好吧好吧好吧...确实! :) 那很简单! :D 非常感谢!
  • 顺便说一句,这不适用于f1, a1 = plt.subplots(); f2, a2 = plt.subplots(sharex=a1)
  • 但是,正如预期的那样,它适用于f1, a1 = plt.subplots(); f2, a2 = plt.subplots(subplot_kw={'sharex': a1})。为什么重复的关键字?
猜你喜欢
  • 2018-10-22
  • 2015-03-30
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-29
  • 2020-02-12
  • 2020-07-15
相关资源
最近更新 更多