mercredi 13 juillet 2016

Can't pickle matplotlib figure: error "Can't pickle 'tkapp' object"

I'm trying to save a matplotlib.pyplot figure using Pickle.

However, I get the following error:

`pickle.PicklingError: Can't pickle 'tkapp' object: <tkapp object at 0x061047B8>

I've read some other posts regarding problems with Pickle, but I've not been able to resolve my issue.

Please note I'm using python 2.7.11 and Matplotlib 1.5.1.

Here is what the code looks like:

import matplotlib.pyplot as plt
from scipy.misc import imread
import pickle

plt.figure()
plt.pot(x,y,label='one')
ax = plt.gca()
img = imread('C:/theview.jpg')
ax.imshow(img, cmap='gray')
ax.invert_yaxis()
legend = plt.legend(numpoints=1)
legend.draggable()
pickle.dump(ax, file(saveFigureAs,'wb')

Aucun commentaire:

Enregistrer un commentaire