【问题标题】:matplotlib sharex across multiple figuresmatplotlib sharex 跨多个数字
【发布时间】:2022-01-26 08:16:41
【问题描述】:

我可以跨子图使用 sharex。但是,我无法跨多个数字使用 sharex。

比如我要创建:

(1) 第一个数字,3 X 2 = 6 个子图

(2) 第二个图,3 X 2 = 6 个子图。

当我放大 12 个子图中的 1 个时,我希望所有 12 个子图都放大到相同的 x 范围。我尝试了下面的代码,但无法让它工作。似乎“ax1”不是sharex的有效输入。任何帮助将不胜感激。谢谢。

import matplotlib.pyplot as plt
fig1, ((ax1,ax2), (ax3,ax4), (ax5, ax6)) = plt.subplots(3,2, sharex = True)
fig2, ((ax11,ax21), (ax31,ax41), (ax51, ax61)) = plt.subplots(3,2, sharex = ax1)

【问题讨论】:

  • 您不能跨人物分享。您可以尝试使用子图。如果您真的需要跨图形共享,您可能必须设置绘制时间回​​调。
  • 是的。我真的需要共享多个地块,例如最多 48 个地块。来自 Matlab 背景,在 Matlab 上很容易实现。我会阅读你提到的所有内容。谢谢!

标签: matplotlib


【解决方案1】:

经过一番挣扎,意识到底部代码可以工作。但不确定这是否是最优化的方式。当其中一个情节被放大时,其余的都随之而来,这就是我们所需要的。

import matplotlib.pyplot as plt
fig = plt.figure()
ax1.fig.add_subplot(3,2,1)
ax2.fig.add_subplot(3,2,2, sharex = ax1)
ax3.fig.add_subplot(3,2,3, sharex = ax1)

fig2 = plt.figure()
ax4.fig2.add_subplot(3,2,1, sharex = ax1)
ax5.fig2.add_subplot(3,2,2, sharex = ax1)
ax6.fig2.add_subplot(3,2,3, sharex = ax1)

【讨论】:

    猜你喜欢
    • 2020-11-24
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 2018-03-23
    • 2016-10-27
    • 1970-01-01
    相关资源
    最近更新 更多