I have a program that creates plots - sometimes line plots, sometimes NonUniformImages - using matplotlib. I'd like to be able to pickle the plots to reopen them at a later time without going through the whole creation process again. For whatever reason, it keeps throwing a PicklingError: Can't pickle 'RendererAgg' object
. I've tried using both import dill as pickle
and import pickle
, as well as all 4 different pickling options but no change.
The axes are defined here:
class Imaging:
def function:
ax1 = plt.subplot(2,1,1)
ax2 = plt.subplot(2,1,2)
And set here: (Imaging.figureProperties is a list and is meant to hold multiple [ax1,ax2]
objects. Also in the same function as where ax1
and ax2
are defined.)
Imaging.figureProperties.append([ax1,ax2])
Finally, data is pickled here (i
is chosen by the user, but it will be within the list):
class2:
with open(filename, 'wb') as f:
pickle.dump(Imaging.figureProperties[i-1],f)
I have no problem running the sample code from this question (with some slight changes such as opening in 'wb'
instead of just 'w'
), as long as I use import dill as pickle
. If I use the standard import pickle
it throws the same PicklingError
. What is going on here?