6

since matplotlib 1.3 matplotlib figures are pickle-able

When I try an example found on stackoverflow:

import matplotlib.pyplot as plt
import numpy as np
import pickle

ax = plt.subplot(111)
x = np.linspace(0, 10)
y = np.exp(x)
plt.plot(x, y)
pickle.dump(ax, file('myplot.pickle', 'w'))

Source: Store and reload matplotlib.pyplot object

I get the following error:

Traceback (most recent call last):
  File "D:/Work/Programming/Experimental/picklematplotlib/main.py", line 15, in <module>
    pickle.dump(ax, file)
  File "C:\Python32\lib\site-packages\six.py", line 116, in __getattr__
    _module = self._resolve()
  File "C:\Python32\lib\site-packages\six.py", line 105, in _resolve
    return _import_module(self.mod)
  File "C:\Python32\lib\site-packages\six.py", line 76, in _import_module
    __import__(name)
  File "C:\Python32\lib\dbm\gnu.py", line 3, in <module>
    from _gdbm import *
ImportError: No module named _gdbm

I am using matplotlib-1.3.1.win-amd64.py3.2.exe version of matplotlib together with python3.2 on an 64bit windows machine

according to: http://docs.python.org/2/library/gdbm.html gdbm is named dbm.gnu in python3. so is it a software bug in matplotlib or what could I do to make it working.

surprisingly the .pickle file is created and useable. this means, the program crashes directly after writing the .pickle file

Community
  • 1
  • 1
der_die_das_jojo
  • 843
  • 1
  • 7
  • 20

1 Answers1

0

Update to matplotlib version 1.3.1 and the script you posted does not give any error (using Python 2.7.6)

Ramon Crehuet
  • 3,279
  • 20
  • 36