You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to pickle.load(fig) with mpl in jupyter notebook #8291
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-23-0e84ab5169e3> in <module>()
15
16 with open('bla.pickle', 'rb') as pickle_file:
---> 17 ax = pickle.load(pickle_file)
18 plt.show()
/home/uni09/cosmo/cbyrohl/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/figure.py in __setstate__(self, state)
1443 allnums = plt.get_fignums()
1444 num = max(allnums) + 1 if allnums else 1
-> 1445 mgr = plt._backend_mod.new_figure_manager_given_figure(num, self)
1446
1447 # XXX The following is a copy and paste from pyplot. Consider
AttributeError: module 'ipykernel.pylab.backend_inline' has no attribute 'new_figure_manager_given_figure'
This code was executed in a jupyter notebook (ipython 5.3)..
When executing as usual python script, it works just fine. It also works fine when dumping in Jupyter and loading in script.
Is it possible to dump the matplotlib plot in Pickle using the default figure manager and load it in Jupyter notebook.
Basically I tried now to save a plot by running a .py file
`
import numpy as np
import matplotlib.pyplot as plt
import pickle
x = np.linspace(-np.pi, np.pi)
y = np.cos(x)
fig, ax = plt.subplots(1, 1)
ax.plot(x, y, label='cos(x)')
ax.set_xlabel('Time (s)')
Activity
tacaswell commentedon Mar 14, 2017
This should be reported against IPython as they maintain the inline backend.
attn @takluyver
cbyrohl commentedon Mar 15, 2017
Sure, I reported this in the ipykernel repository.
takluyver commentedon Mar 15, 2017
@tacaswell is it easy to implement the
new_figure_manager_given_figurefunction? I'm not familiar with what's required for a mpl backend.FIX: add missing import from backend_agg
tacaswell commentedon Jan 12, 2020
3 years on I finally came back to this...
tacaswell commentedon Jan 20, 2020
Closed by #16189 and ipython/ipykernel#476
FIX: add missing import from backend_agg
brianjoubert commentedon Dec 28, 2022
Hello,
Is it possible to dump the matplotlib plot in Pickle using the default figure manager and load it in Jupyter notebook.
Basically I tried now to save a plot by running a .py file
`
import numpy as np
import matplotlib.pyplot as plt
import pickle
x = np.linspace(-np.pi, np.pi)
y = np.cos(x)
fig, ax = plt.subplots(1, 1)
ax.plot(x, y, label='cos(x)')
ax.set_xlabel('Time (s)')
pickle.dump((fig, ax), open('myplot.pickle', 'wb'))
`
and then load the produced pickle in a Jupyter Notebook:
`
import matplotlib.pyplot as plt
import pickle
fig, ax = pickle.load(open('myplot.pickle', 'rb'))
ax.set_ylabel('Voltage (mV)')
ax.minorticks_on()
ax.legend()
`
I always get the following message.
AttributeError: 'NoneType' object has no attribute 'new_figure_manager_given_figure'jklymak commentedon Dec 28, 2022
Please open a new issue.