在matplotlib中的新supblot中重新绘制现有图形

在matplotlib中的新supblot中重新绘制现有图形,matplotlib,subplot,Matplotlib,Subplot,比如说,在可视化数据的过程中,我后来决定将两个在子图中有大量注释的现有图组合起来,在同一个窗口中并排比较 是的,我可以回去在一个子地块上重新创建这些。但是,有没有一种方法可以让我抓取轴或图形手柄——我不知道它们是如何工作的——无论是什么方法都可以捕获单个图形的所有内容,并使用数据来创建新的子图形 类似于 from numpy.random import seed from numpy.random import randint import matplotlib.pyplot as plt

比如说,在可视化数据的过程中,我后来决定将两个在子图中有大量注释的现有图组合起来,在同一个窗口中并排比较

是的,我可以回去在一个子地块上重新创建这些。但是,有没有一种方法可以让我抓取轴或图形手柄——我不知道它们是如何工作的——无论是什么方法都可以捕获单个图形的所有内容,并使用数据来创建新的子图形

类似于

from numpy.random import seed
from numpy.random import randint
import matplotlib.pyplot as plt    

x=list(range(1,11))
seed(1)
y1= randint(5, 35, 10)
seed(2)
y2= randint(5, 35, 10)
seed(3)
y3=randint(5, 35, 10)

fig1=plt.figure(1)
ax1=plt.plot(x,y1,x,y2,x,y3)
plt.xlabel('Xaxis')
plt.ylabel('yaxis')
plt.title('Some Plot')
plt.text(10,10, 'some text')

fig2=plt.figure(2)
ax2= plt.plot(x,y1+y2+y3)

# later, I say decided I wanted to also display the two plots as subplots in the same window.
fig3=pltfigure(3)
plt.subplot(2,1,1)
plt.plot(ax1) # plt.plot(fig1.lines),plt.plot(fig1)
plt.subplot(2,1,2)
plt.plot(ax2)

我正在寻找一种简单的方法来获取图1和图2中已经绘制的所有内容,并将其直接传递到图3中的子地块。

代码中的每个
ax1
ax2
都是
Line2D
的列表。您可以使用
提取线的数据。获取数据()
并打印:

# later, I say decided I wanted to also display the two plots as subplots in the same window.
fig3=plt.figure(3)
plt.subplot(2,1,1)
for line in ax1:
    plt.plot(*line.get_data())
plt.subplot(2,1,2)
for line in ax1:
    plt.plot(*line.get_data())
输出: