猿问

将现有的轴或图形作为子图形添加到新图形中

我有四个图形和轴对象,我想将它们作为子图添加到新图形中。即如下代码:


fig1, ax1 = plt.subplots(1, 1, num=1)

ax1.plot(x1, y1)


fig2, ax2 = plt.subplots(1, 1, num=2)

ax2.plot(x2, y2)


fig3, ax3 = plt.subplots(1, 1, num=3)

ax3.plot(x3, y3)


fig4, ax4 = plt.subplots(1, 1, num=4)

ax4.plot(x4, y4)

我希望所有的ax1都是ax4新图中的子图fig5,如下所示:(这不是有效的代码,仅用于说明目的)


fig5 = plt.figure()

fig5.subplot(2, 2, 1) = ax1

fig5.subplot(2, 2, 2) = ax2

fig5.subplot(2, 2, 3) = ax3

fig5.subplot(2, 2, 4) = ax4

做这个的最好方式是什么?


我正在使用 Matplotlib 版本 3.3.1。


慕尼黑的夜晚无繁华
浏览 104回答 1
1回答

慕容3067478

你离我们并不遥远。您只需将其附加到新的即可。fig5 = plt.figure()fig5.axes.append(ax1) # ax2 etc
随时随地看视频慕课网APP

相关分类

Python
我要回答