I am plotting very big data sets and to save time I like storing my matplotlib plots with pickle and retrieving them later so that I can make minor format changes without having to process all the data every time:
import matplotlib.pyplot as plt
import pickle as pkl
# generating the plot and drawing the data
fig, ax = plt.subplots()
ax.plot(...)
# storing either fig or ax as pickle, doesn't really make a difference
pkl.dump(ax, open('plot.pkl','wb'))
Now it would be really nice, if I could use these stored plots as subplots in the final figure like this:
fig, (ax1, ax2) = plt.subplots(1,2)
ax1 = pkl.load('plot1.pkl','rb')
ax2 = pkl.load('plot2.pkl', 'rb')
plt.show()
I know that this code won't work, but is there any way to achieve this? I have always thought that it is mandatory to first generate empty subplots and draw into them later but maybe there is a workaround.
As always, any help is highly appreciated.