Saving png figures matplotlib 3.3.0 results in "AttributeError: __delete__"
See original GitHub issueDescribe the issue
When trying to save png figures with ipympl, interactive widgets, and the latest matplotlib (3.3.0), the saving fails with the following error message:
import matplotlib
matplotlib.use('module://ipympl.backend_nbagg')
from matplotlib import pyplot as plt
fig = plt.figure()
fig.savefig('test.png')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-c4b3ac84131c> in <module>
6 from matplotlib import pyplot as plt
7 fig = plt.figure()
----> 8 fig.savefig('test.png')
/usr/local/lib/python3.8/dist-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)
2309 patch.set_edgecolor('none')
2310
-> 2311 self.canvas.print_figure(fname, **kwargs)
2312
2313 if transparent:
/usr/local/lib/python3.8/dist-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2223 self.figure.set_edgecolor(origedgecolor)
2224 self.figure.set_canvas(self)
-> 2225 return result
2226
2227 @classmethod
/usr/lib/python3.8/contextlib.py in __exit__(self, type, value, traceback)
118 if type is None:
119 try:
--> 120 next(self.gen)
121 except StopIteration:
122 return False
/usr/local/lib/python3.8/dist-packages/matplotlib/cbook/__init__.py in _setattr_cm(obj, **kwargs)
2064 for attr, orig in origs.items():
2065 if orig is sentinel:
-> 2066 delattr(obj, attr)
2067 else:
2068 setattr(obj, attr, orig)
AttributeError: __delete__
Saving figures as pdf
or png
figures with an older Matplotlib version (3.2.0) works well.
Versions
Matplotlib version: 3.3.0
python -c "import sys; print('\n',sys.version); import ipympl; print('ipympl version:', ipympl.__version__)" && jupyter --version && jupyter nbextension list && jupyter labextension list
–>
3.8.5 (default, Jul 20 2020, 18:32:44)
[GCC 9.3.0]
ipympl version: 0.5.7
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.7.4
ipython : 7.16.1
ipykernel : 5.3.4
jupyter client : 6.1.6
jupyter lab : 2.2.2
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.7
traitlets : 4.3.3
Known nbextensions:
config dir: /usr/etc/jupyter/nbconfig
notebook section
jupyter-js-widgets/extension disabled
config dir: /usr/local/etc/jupyter/nbconfig
notebook section
bqplot/extension enabled
- Validating: OK
itkwidgets/extension enabled
- Validating: OK
jupyter-datawidgets/extension enabled
- Validating: OK
jupyter-leaflet/extension enabled
- Validating: OK
jupyter-matplotlib/extension enabled
- Validating: OK
jupyter-js-widgets/extension enabled
- Validating: OK
config dir: /etc/jupyter/nbconfig
notebook section
jupyter-js-widgets/extension enabled
- Validating: OK
JupyterLab v2.2.2
Known labextensions:
app dir: /usr/local/share/jupyter/lab
@jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK
@jupyterlab/hub-extension v2.0.2 enabled OK
jupyter-matplotlib v0.7.3 enabled OK
jupyterlab-datawidgets v6.3.0 enabled OK
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:21 (9 by maintainers)
Top Results From Across the Web
python - AttributeError: __delete__ when saving figure in ...
it seems this error was introduced from matplotlib 3.3.0. So currently, my solution is downgrading matplotlib to 3.2.2.
Read more >matplotlib.figure.Figure — Matplotlib 3.3.4 documentation
Clear the figure. Set keep_observers to True if, for example, a gui widget is tracking the axes in the figure.
Read more >matplotlib.figure — Matplotlib 3.6.2 documentation
This is default for all artists, so calling Figure.legend without any arguments and without setting the labels manually will result in no legend...
Read more >API Changes — Matplotlib 3.3.3 documentation
These methods now assume that the figure edge and facecolor have been correctly applied by FigureCanvasBase.print_figure , as they are normally ...
Read more >GitHub Stats — Matplotlib 3.3.0 documentation
PR #17027: Fix saving nbAgg figure after a partial blit ... PR #16781: Update image tutorial wrt. removal of native png handler.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For me it was fixed with the new release 0.5.8 after the fix from @ianhi . But I have to admit I moved on to the next matplotlib release already. Are you using ipympl 0.5.8?
Edit: I just saw on the readme page that ipympl 0.5.8 requires matplotlib 3.3.1. Couldn’t you move to this one? Or is 3.3.0 necessary?
and if this fixes the problem, then I would say this is the optimal solution as it does not involve core Matplotlib picking up any more complexity and reduces the exposed public surface on the ipympl side.