0

Is it possible to "copy/paste" figures into a subplot?

Let's say that you have created two figures

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd

d = pd.DataFrame({'Time': np.linspace(0,10)})
d["Exp"] =np.exp(d["Time"])
d["Sin"] =np.sin(d["Time"])

f1,a1 =  plt.subplots(1, 1)
sns.scatterplot(data=d,x='Time',y='Sin',ax=a1)

Sin(x)

f2,a2 =  plt.subplots(1, 1)
sns.scatterplot(data=d,x='Time',y='Exp',ax=a2)

Exp(x)

Further down in program I then want to include these plots in a new figure with subplots. Reploting is not desired as the figure/axes in my project is outputs from a function.

I am not sure how to to do this, so I tried :

f3,a3=plt.subplots(2, 1)
a3[0]=a1
a3[3]=a2
f3

But that did not produce the desired result

enter image description here

  • Although you state you don't want to replot, the strongly recommended approach is to add an `ax` parameter to the surrounding function and plot onto that ax. – JohanC Feb 03 '22 at 18:58

0 Answers0