0

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.

zeawoas
  • 446
  • 7
  • 18
  • The underlying principle is shown in [this question](https://stackoverflow.com/questions/6309472/matplotlib-can-i-create-axessubplot-objects-then-add-them-to-a-figure-instance). – ImportanceOfBeingErnest Mar 24 '18 at 10:41
  • Thanks! Don't know how I did not find this thread at first, sorry for the duplicate. – zeawoas Mar 24 '18 at 11:40

0 Answers0