gpt4 book ai didi

python - 如何使用 Matplotlib 从现有轴执行子图

转载 作者:行者123 更新时间:2023-12-01 03:32:21 25 4
gpt4 key购买 nike

我想将来自程序不同部分的两个(或更多)轴(在我的示例中为 ax1 和 ax2 )添加到一个独特的原始 .

因此,在我的程序的第一部分中,我会这样做:

fig1, ax1 = plt.subplots(1, 1)
ax1.scatter(...)
ax1.imshow()
...

在同一程序的第二部分中:

fig2, ax2 = plt.subplots(1, 1)
ax2.plot(...)
...

然后我想构建一个图形来合并这两个轴 ax1ax2,类似于:

fig = plt.figure()
fig.add_my_subplots(ax1, ax2)

最佳答案

由于轴似乎不应链接/添加到 Matplotlib 中的另一个 Figure,我想出了一个更简单的解决方案:

fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True)
do_my_stuff_with_first_axis(ax=ax1)
do_my_stuff_with_second_axis(ax=ax2)

关于python - 如何使用 Matplotlib 从现有轴执行子图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40742896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com