matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.59k stars 226 forks source link

issue computing repr of `Figure` #115

Open tacaswell opened 5 years ago

tacaswell commented 5 years ago

Due to https://github.com/matplotlib/matplotlib/pull/10292 during a save operation we temporarily remove the manager

%matplotlib widget
import matplotlib.pyplot as plt
plt.plot(range(5))
fig = plt.gcf()

## new cell
fig

and you will get a traceback that looks like:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
    242 
    243     if 'png' in formats:
--> 244         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    245     if 'retina' in formats or 'png2x' in formats:
    246         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

~/.virtualenvs/bleeding/lib/python3.9/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    126 
    127     bytes_io = BytesIO()
--> 128     fig.canvas.print_figure(bytes_io, **kw)
    129     data = bytes_io.getvalue()
    130     if fmt == 'svg':

~/source/p/mpl-master/lib/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
   2058             if bbox_inches:
   2059                 if bbox_inches == "tight":
-> 2060                     renderer = _get_renderer(
   2061                         self.figure,
   2062                         functools.partial(

~/source/p/mpl-master/lib/matplotlib/backend_bases.py in _get_renderer(figure, print_method)
   1546     with cbook._setattr_cm(figure, draw=_draw):
   1547         try:
-> 1548             print_method(io.BytesIO())
   1549         except Done as exc:
   1550             figure._cachedRenderer, = exc.args

~/source/p/mpl-master/lib/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args, **kwargs)
    533 
    534         else:
--> 535             FigureCanvasAgg.draw(self)
    536             renderer = self.get_renderer()
    537             with cbook._setattr_cm(renderer, dpi=self.figure.dpi), \

~/source/p/mpl-master/lib/matplotlib/backends/backend_agg.py in draw(self)
    391         self.renderer = self.get_renderer(cleared=True)
    392         # Acquire a lock on the shared font cache.
--> 393         with RendererAgg.lock, \
    394              (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    395               else nullcontext()):

~/source/other_source/cpython/Lib/contextlib.py in __enter__(self)
    111         del self.args, self.kwds, self.func
    112         try:
--> 113             return next(self.gen)
    114         except StopIteration:
    115             raise RuntimeError("generator didn't yield") from None

~/source/p/mpl-master/lib/matplotlib/backend_bases.py in _wait_cursor_for_draw_cm(self)
   2732         if self._draw_time - last_draw_time > 1:
   2733             try:
-> 2734                 self.set_cursor(cursors.WAIT)
   2735                 yield
   2736             finally:

~/source/p/mpl-master/lib/matplotlib/backends/backend_webagg_core.py in set_cursor(self, cursor)
    379     def set_cursor(self, cursor):
    380         if cursor != self.cursor:
--> 381             self.canvas.send_event("cursor", cursor=cursor)
    382         self.cursor = cursor
    383 

~/source/p/mpl-master/lib/matplotlib/backends/backend_webagg_core.py in send_event(self, event_type, **kwargs)
    344 
    345     def send_event(self, event_type, **kwargs):
--> 346         self.manager._send_event(event_type, **kwargs)
    347 
    348 

AttributeError: 'NoneType' object has no attribute '_send_event'

I thought we should be going through https://github.com/matplotlib/matplotlib/blob/59b5e0e873dd3420758498c90b15f7f70cb007da/lib/matplotlib/figure.py#L403-L408 but it looks like we are going trough a lambda from IPython core....

I think this could legitimately go against IPython, Matplotlib, or here. Leaving here as the "middle ground" ;)

tacaswell commented 5 years ago

And there is a timing race here, if you run the second cell with in a second of the first it works ok as the timeout on displaying the "I'm drawing" cursor is not hit.

I am testing with master branch IPython, Matplotlib, and ipympl.

SylvainCorlay commented 5 years ago

I am not reproducing that issue locally at the moment. Will look more into it tomorrow.

tacaswell commented 5 years ago

I think this may require mpl master to reproduce...

stonebig commented 5 years ago

the problem is still there. Looking at @tacaswell link, there seems to be a wired Matplotlib thing "during a save operation we temporarily remove the manager" , that may explain other random un-correct display I have on the widget

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backend_bases.py in _wait_cursor_for_draw_cm(self)
   2779             try:
-> 2780                 self.set_cursor(cursors.WAIT)
   2781                 yield

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backends\backend_webagg_core.py in set_cursor(self, cursor)
    380         if cursor != self.cursor:
--> 381             self.canvas.send_event("cursor", cursor=cursor)
    382         self.cursor = cursor

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backends\backend_webagg_core.py in send_event(self, event_type, **kwargs)
    345     def send_event(self, event_type, **kwargs):
--> 346         self.manager._send_event(event_type, **kwargs)
    347 

AttributeError: 'NoneType' object has no attribute '_send_event'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
    242 
    243     if 'png' in formats:
--> 244         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    245     if 'retina' in formats or 'png2x' in formats:
    246         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    126 
    127     bytes_io = BytesIO()
--> 128     fig.canvas.print_figure(bytes_io, **kw)
    129     data = bytes_io.getvalue()
    130     if fmt == 'svg':

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
   2077                         self.figure,
   2078                         functools.partial(
-> 2079                             print_method, dpi=dpi, orientation=orientation))
   2080                     self.figure.draw(renderer)
   2081                     bbox_artists = kwargs.pop("bbox_extra_artists", None)

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backend_bases.py in _get_renderer(figure, print_method)
   1548     with cbook._setattr_cm(figure, draw=_draw):
   1549         try:
-> 1550             print_method(io.BytesIO())
   1551         except Done as exc:
   1552             figure._cachedRenderer, = exc.args

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args, **kwargs)
    516         }
    517 
--> 518         FigureCanvasAgg.draw(self)
    519         if pil_kwargs is not None:
    520             from PIL import Image

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
    393         with RendererAgg.lock, \
    394              (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
--> 395               else nullcontext()):
    396             self.figure.draw(self.renderer)
    397             # A GUI class may be need to update a window using this draw, so

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\contextlib.py in __enter__(self)
    110         del self.args, self.kwds, self.func
    111         try:
--> 112             return next(self.gen)
    113         except StopIteration:
    114             raise RuntimeError("generator didn't yield") from None

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backend_bases.py in _wait_cursor_for_draw_cm(self)
   2781                 yield
   2782             finally:
-> 2783                 self.set_cursor(self._lastCursor)
   2784         else:
   2785             yield

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backends\backend_webagg_core.py in set_cursor(self, cursor)
    379     def set_cursor(self, cursor):
    380         if cursor != self.cursor:
--> 381             self.canvas.send_event("cursor", cursor=cursor)
    382         self.cursor = cursor
    383 

C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\lib\site-packages\matplotlib\backends\backend_webagg_core.py in send_event(self, event_type, **kwargs)
    344 
    345     def send_event(self, event_type, **kwargs):
--> 346         self.manager._send_event(event_type, **kwargs)
    347 
    348 

AttributeError: 'NoneType' object has no attribute '_send_event'
stonebig commented 5 years ago

windows 10 / Python - 3.7.5, and

Package                       Version     
----------------------------- ------------
absl-py                       0.8.1       
adodbapi                      2.6.0.7     
affine                        2.3.0       
aiofiles                      0.4.0       
aiosqlite                     0.10.0      
alabaster                     0.7.12      
altair                        3.2.0       
altair-transform              0.1.0       
altair-widgets                0.2.2       
altgraph                      0.16.1      
aniso8601                     8.0.0       
ansiwrap                      0.8.4       
appdirs                       1.4.3       
asciitree                     0.3.3       
asteval                       0.9.16      
astor                         0.8.0       
astroid                       2.3.2       
astroML                       0.4.1       
astropy                       3.2.3       
atomicwrites                  1.3.0       
attrs                         19.3.0      
autopep8                      1.4.4       
Babel                         2.7.0       
backcall                      0.1.0       
backports-abc                 0.5         
baresql                       0.7.6       
bcolz                         1.2.1       
bcrypt                        3.1.6       
beautifulsoup4                4.8.1       
black                         19.3b0      
bleach                        3.1.0       
blinker                       1.4         
blosc                         1.8.1       
bloscpack                     0.16.0      
bokeh                         1.4.0rc2    
Bottleneck                    1.2.1       
bqplot                        0.12.0      
branca                        0.3.1       
brewer2mpl                    1.4.1       
Brotli                        1.0.7       
cachetools                    3.1.1       
Cartopy                       0.17.0      
certifi                       2019.9.11   
cffi                          1.13.1      
cftime                        1.0.4.2     
chardet                       3.0.4       
Click                         7.0         
click-default-group           1.2.2       
click-plugins                 1.1.1       
cligj                         0.5.0       
cloudpickle                   1.2.2       
clrmagic                      0.0.1a2     
colorama                      0.4.1       
colorcet                      2.0.2       
comtypes                      1.1.7       
cryptography                  2.8         
cvxopt                        1.2.3       
cvxpy                         1.0.25      
cx-Freeze                     6.0         
cycler                        0.10.0      
cyordereddict                 1.0.0       
Cython                        0.29.13     
cytoolz                       0.10.0      
dask                          2.6.0       
dask-searchcv                 0.2.0       
databases                     0.2.5       
datasette                     0.30.0      
datashader                    0.8.0       
datashape                     0.5.2       
db.py                         0.5.3       
decorator                     4.4.1       
defusedxml                    0.6.0       
Deprecated                    1.2.6       
descartes                     1.1.0       
dill                          0.3.1.1     
distributed                   2.6.0       
docopt                        0.6.2       
docrepr                       0.1.1       
docutils                      0.15.2      
ecos                          2.0.7.post1 
edward                        1.3.5       
emcee                         3.0.1       
entrypoints                   0.3         
fast-histogram                0.7         
fasteners                     0.15        
fastparquet                   0.3.2       
feather-format                0.4.0       
Fiona                         1.8.9       
Flask                         1.1.1       
flask-accepts                 0.15.0      
flask-restplus                0.13.0      
flaskerize                    0.12.0      
formlayout                    2.0.0a0     
fs                            2.4.11      
fsspec                        0.5.2       
future                        0.18.1      
fuzzywuzzy                    0.17.0      
gast                          0.2.2       
GDAL                          3.0.1       
geographiclib                 1.50        
geopandas                     0.6.1       
geopy                         1.20.0      
geoviews                      1.6.5       
gmpy2                         2.0.8       
google-auth                   1.6.3       
google-auth-oauthlib          0.4.1       
google-pasta                  0.1.7       
greenlet                      0.4.15      
grpcio                        1.24.3      
guidata                       1.7.6       
guiqwt                        3.0.3       
h11                           0.9.0       
h2                            3.1.1       
h5py                          2.10.0      
HeapDict                      1.0.1       
holoviews                     1.12.6      
hpack                         3.0.0       
html5lib                      1.0.1       
hupper                        1.9         
husl                          4.0.3       
hvplot                        0.5.2       
Hypercorn                     0.9.0+dev   
hyperframe                    5.2.0       
hypothesis                    4.41.3      
idlex                         1.18        
idna                          2.8         
imageio                       2.6.1       
imageio-ffmpeg                0.3.0       
imagesize                     1.1.0       
imbalanced-learn              0.5.0       
importlib-metadata            0.23        
intake                        0.5.3       
ipydatawidgets                4.0.1       
ipykernel                     5.1.3       
ipyleaflet                    0.11.4      
ipympl                        0.3.3       
ipyparallel                   6.2.4       
ipython                       7.9.0       
ipython-genutils              0.2.0       
ipython-sql                   0.3.9       
ipywidgets                    7.5.1       
isort                         4.3.21      
itsdangerous                  1.1.0       
jedi                          0.15.1      
Jinja2                        2.10.3      
joblib                        0.14.0      
json5                         0.8.5       
jsonschema                    3.1.1       
julia                         0.5.0       
jupyter                       1.0.0       
jupyter-client                5.3.4       
jupyter-console               6.0.0       
jupyter-core                  4.6.1       
jupyter-server                0.1.1       
jupyter-sphinx                0.2.1       
jupyterlab                    1.1.4       
jupyterlab-launcher           0.13.1      
jupyterlab-pygments           0.1.0       
jupyterlab-server             1.0.6       
Keras                         2.3.1       
Keras-Applications            1.0.8       
Keras-Preprocessing           1.1.0       
keras-vis                     0.4.1       
keyring                       19.2.0      
kiwisolver                    1.1.0       
lazy-object-proxy             1.4.3       
llvmlite                      0.30.0      
lmfit                         0.9.14      
locket                        0.2.0       
loky                          2.6.0       
lxml                          4.4.1       
Markdown                      3.1.1       
MarkupSafe                    1.1.1       
marshmallow                   3.2.1       
matplotlib                    3.2.0rc1    
mccabe                        0.6.1       
mercantile                    1.1.2       
metakernel                    0.24.3      
mistune                       0.8.4       
mizani                        0.6.0       
mkl-service                   2.3.0       
mlxtend                       0.17.0      
monotonic                     1.5         
more-itertools                7.2.0       
moviepy                       1.0.1       
mpl-scatter-density           0.6         
mpld3                         0.3         
mpldatacursor                 0.6.2       
mpmath                        1.1.0       
msgpack                       0.6.2       
multidict                     4.5.2       
multipledispatch              0.6.0       
multiprocess                  0.70.9      
munch                         2.4.0       
mypy                          0.740       
mypy-extensions               0.4.3       
mysql-connector-python        8.0.18      
nbconvert                     5.6.1       
nbconvert-reportlab           0.2         
nbformat                      4.4.0       
netCDF4                       1.5.3       
networkx                      2.4         
nltk                          3.4.5       
notebook                      6.0.1       
numba                         0.46.0      
numcodecs                     0.6.3       
numdifftools                  0.9.39      
numexpr                       2.7.0       
numpy                         1.17.3+mkl  
numpydoc                      0.9.1       
oauthlib                      3.1.0       
oct2py                        5.0.4       
octave-kernel                 0.31.0      
opt-einsum                    3.1.0       
osqp                          0.6.1       
packaging                     19.2        
palettable                    3.3.0       
pandas                        0.25.3      
pandas-datareader             0.8.1       
pandocfilters                 1.4.2       
panel                         0.6.4       
papermill                     1.2.1       
param                         1.9.2       
parambokeh                    0.2.3       
paramiko                      2.6.0       
paramnb                       2.0.4       
parso                         0.5.1       
partd                         1.0.0       
passlib                       1.7.1       
patsy                         0.5.1       
pdfrw                         0.4         
pdvega                        0.2.1.dev0  
pefile                        2019.4.18   
pep8                          1.7.1       
pexpect                       4.7.0+dummy 
pg8000                        1.13.1      
pickleshare                   0.7.5       
Pillow                        6.2.1       
Pint                          0.9         
pip                           19.3.1      
pkginfo                       1.5.0.1     
plotnine                      0.6.0       
pluggy                        0.13.0      
ply                           3.11        
portalocker                   1.5.1       
ppci                          0.5.6       
prettytable                   0.7.2       
priority                      1.3.0       
proglog                       0.1.9       
prometheus-client             0.7.1       
prompt-toolkit                2.0.10      
protobuf                      3.10.0      
psutil                        5.6.3       
ptpython                      2.0.6       
PuLP                          1.6.10      
py                            1.8.0       
pyarrow                       0.15.0      
pyasn1                        0.4.7       
pyasn1-modules                0.2.7       
PyAudio                       0.2.11      
pybars3                       0.9.6       
pybind11                      2.4.3       
pycodestyle                   2.5.0       
pycosat                       0.6.3       
pycparser                     2.19        
pyct                          0.4.6       
pyepsg                        0.4.0       
pyflakes                      2.1.1       
pyflux                        0.4.17      
pygame                        1.9.6       
pygbm                         0.1.0       
Pygments                      2.4.2       
pyhdf                         0.10.1      
PyInstaller                   3.5         
pylint                        2.4.3       
pymc                          2.3.7       
PyMeta3                       0.5.1       
pymongo                       3.9.0       
PyNaCl                        1.3.0       
pyodbc                        4.0.27      
PyOpenGL                      3.1.3b2     
pypandoc                      1.3.2       
pyparsing                     2.4.2       
pypiwin32                     223+dummy   
pyproj                        2.4.0       
PyQt5                         5.13.1      
PyQt5-sip                     4.19.19     
pyqtgraph                     0.11.0.dev0 
PyQtWebEngine                 5.13.1      
pyrsistent                    0.15.5      
pyserial                      3.4         
pyshp                         2.1.0       
pystache                      0.5.4       
pytest                        5.2.2       
python-dateutil               2.8.0       
python-hdf4                   0.10.0+dummy
python-jsonrpc-server         0.2.0       
python-language-server        0.29.2      
python-Levenshtein            0.12.0      
python-snappy                 0.5.4       
pythonnet                     2.4.0       
PythonQwt                     0.5.6.dev0  
pythreejs                     2.1.1       
pytz                          2019.3      
pyviz-comms                   0.7.2       
PyWavelets                    1.1.1       
pywin32                       225         
pywin32-ctypes                0.2.0       
pywinpty                      0.5.5       
pywinusb                      0.4.2       
PyYAML                        5.1.2       
pyzmq                         18.1.0      
pyzo                          4.9.0       
QtAwesome                     0.6.0       
qtconsole                     4.5.5       
QtPy                          1.9.0       
quantecon                     0.4.5       
Quart                         0.10.0      
rasterio                      1.1.0       
readme-renderer               24.0        
redis                         3.3.11      
regex                         2019.8.19   
reportlab                     3.5.31      
requests                      2.22.0      
requests-oauthlib             1.2.0       
requests-toolbelt             0.9.1       
rise                          5.5.1       
rope                          0.14.0      
rpy2                          2.9.5       
rsa                           4.0         
Rtree                         0.8.3       
ruamel.yaml                   0.16.5      
ruamel.yaml.clib              0.2.0       
Rx                            3.0.1       
scikit-fuzzy                  0.4.1       
scikit-image                  0.16.2      
scikit-learn                  0.21.3      
scikit-optimize               0.5.2       
scilab2py                     0.6.2       
scipy                         1.3.1       
scs                           2.1.1.post2 
seaborn                       0.9.1.dev0  
Send2Trash                    1.5.0       
setuptools                    41.6.0      
Shapely                       1.6.4.post2 
simplegeneric                 0.8.1       
simplejson                    3.16.0      
simpy                         3.0.11      
six                           1.12.0      
snakeviz                      2.0.1       
snowballstemmer               2.0.0       
snuggs                        1.4.7       
sortedcontainers              2.1.0       
sounddevice                   0.3.14      
soupsieve                     1.9.4       
Sphinx                        2.2.1       
sphinx-rtd-theme              0.4.3       
sphinxcontrib-applehelp       1.0.1       
sphinxcontrib-devhelp         1.0.1       
sphinxcontrib-htmlhelp        1.0.2       
sphinxcontrib-jsmath          1.0.1       
sphinxcontrib-qthelp          1.0.2       
sphinxcontrib-serializinghtml 1.1.3       
spyder                        3.3.6       
spyder-kernels                0.5.1       
SQLAlchemy                    1.3.10      
sqlite-bro                    0.9.1       
sqlparse                      0.3.0       
statsmodels                   0.10.1      
streamz                       0.5.0       
supersmoother                 0.4         
swifter                       0.292       
sympy                         1.4         
tables                        3.6.1       
tblib                         1.5.0       
tenacity                      5.1.4       
tensorboard                   2.0.1       
tensorflow                    2.0.0       
tensorflow-estimator          2.0.1       
tensorflow-probability        0.8.0       
termcolor                     1.1.0       
terminado                     0.8.2       
testpath                      0.4.2       
textwrap3                     0.9.2       
thrift                        0.11.0      
toml                          0.10.0      
toolz                         0.10.0      
torch                         1.3.0+cpu   
torchvision                   0.4.1+cpu   
tornado                       6.0.3       
tqdm                          4.36.1      
traitlets                     4.3.3       
traittypes                    0.2.1       
twine                         2.0.0       
twitter                       1.17.1      
typed-ast                     1.4.0       
typing-extensions             3.7.4.1     
tzlocal                       1.5.1       
uncertainties                 3.1.2       
urllib3                       1.25.6      
uvicorn                       0.10.2      
vega                          2.6.0       
vega-datasets                 0.7.0       
ViTables                      3.0.0       
voila                         0.1.17      
wcwidth                       0.1.7       
webencodings                  0.5.1       
websockets                    8.0.2       
Werkzeug                      0.16.0      
wheel                         0.33.6      
widgetsnbextension            3.5.1       
winpython                     2.2.20191022
winrt                         1.0.19128.1 
wordcloud                     1.5.0       
wrapt                         1.11.2      
wsproto                       0.15.0      
xarray                        0.14.0      
xlrd                          1.2.0       
XlsxWriter                    1.2.2       
xlwings                       0.16.0      
zarr                          2.3.2       
zict                          1.0.0       
zipp                          0.5.2 

and

!jupyter labextension list
JupyterLab v1.1.4
Known labextensions:
   app dir: C:\WinP\bd37\bu\WPy64-3750b1\python-3.7.5.amd64\share\jupyter\lab
        @bokeh/jupyter_bokeh v1.1.0 enabled  ok
        @jupyter-voila/jupyterlab-preview v0.1.3 enabled  ok
        @jupyter-widgets/jupyterlab-manager v1.0.3 enabled  ok
        @jupyterlab/vega3-extension v1.0.0 enabled  ok
        @pyviz/jupyterlab_pyviz v0.8.0 enabled  ok
        bqplot v0.5.0 enabled  ok
        jupyter-leaflet v0.11.4 enabled  ok
        jupyter-matplotlib v0.4.2 enabled  ok
        jupyter-threejs v2.1.1 enabled  ok
        jupyterlab-datawidgets v6.2.0 enabled  ok
        jupyterlab_bokeh v1.0.0 enabled  ok
stonebig commented 4 years ago

reverting https://github.com/matplotlib/jupyter-matplotlib/pull/5 makes the thing work again. can it be done as a temporary solution ?

beckermr commented 4 years ago

I think I hit this bug, but now even calling the save right after doesn't help.

@tacaswell @SylvainCorlay @stonebig any ideas?

stonebig commented 4 years ago

on a notebook with a %matplotlib widget at first encounter, it seems ok. if before that moment there was a %matplotlib inline, it's not ok. (on unbiased current version of mpl and ipympl)

beckermr commented 4 years ago

I only used %matplotlib notebook and saw this issue. I switched to %matplotlib inline and it went away.

MaximilianHoffmann commented 4 years ago

I have the same problem with %matplotlib widget, and I do not want to switch to inline plotting. Is there a work around?

vman049 commented 4 years ago

I only used %matplotlib notebook and saw this issue. I switched to %matplotlib inline and it went away.

I also had the same issue and downgraded my matplotlib version from 3.2.0 to 3.1.3. %matplotlib notebook now works.

tacaswell commented 4 years ago

I think this is fixed with mpl 3.2.1

scimax commented 4 years ago

I think this is fixed with mpl 3.2.1

After updating mpl to version 3.3.0 (and also other packages) I thought it would be gone, but now I have a different exception. My traceback reads as follows:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-87b77c9746c5> in <module>
     11 plt.axis('off')
     12 
---> 13 fig.savefig("test.png", bbox_inches='tight')

~\.conda\envs\jlab\lib\site-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:

~\.conda\envs\jlab\lib\site-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

~\.conda\envs\jlab\lib\contextlib.py in __exit__(self, type, value, traceback)
     86         if type is None:
     87             try:
---> 88                 next(self.gen)
     89             except StopIteration:
     90                 return False

~\.conda\envs\jlab\lib\site-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__

I haven't seen this AttributeError before.

My packages, in case it's helpful:

# packages in environment at C:\...
#
# Name                    Version                   Build  Channel
altair                    4.1.0                      py_1    conda-forge
astroid                   2.4.2            py36h9f0ad1d_0    conda-forge
astropy                   4.0.1.post1      py36h68a101e_0    conda-forge
attrs                     19.3.0                     py_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.1                      py_0    conda-forge
beautifulsoup4            4.9.1            py36h9f0ad1d_0    conda-forge
blas                      1.0                         mkl
bleach                    3.1.5              pyh9f0ad1d_0    conda-forge
bokeh                     2.1.1            py36h9f0ad1d_0    conda-forge
brotlipy                  0.7.0           py36h779f372_1000    conda-forge
ca-certificates           2020.6.20            hecda079_0    conda-forge
certifi                   2020.6.20        py36h9f0ad1d_0    conda-forge
cffi                      1.14.1           py36hef61171_0    conda-forge
chardet                   3.0.4           py36h9f0ad1d_1006    conda-forge
cloudpickle               1.5.0                      py_0    conda-forge
colorama                  0.4.3                      py_0    conda-forge
cryptography              3.0              py36hef61171_0    conda-forge
cycler                    0.10.0                     py_2    conda-forge
cytoolz                   0.10.1           py36hfa6e2cd_0    conda-forge
dask-core                 2.21.0                     py_0    conda-forge
decorator                 4.4.2                      py_0    conda-forge
defusedxml                0.6.0                      py_0    conda-forge
entrypoints               0.3             py36h9f0ad1d_1001    conda-forge
enum34                    1.1.10           py36h9f0ad1d_1    conda-forge
fastcache                 1.1.0            py36h68a101e_1    conda-forge
freetype                  2.10.2               hd328e21_0    conda-forge
future                    0.18.2           py36h9f0ad1d_1    conda-forge
gif                       1.0.2                    pypi_0    pypi
gitdb                     4.0.5                      py_0    conda-forge
gitpython                 3.1.3                      py_0    conda-forge
h5py                      2.10.0          nompi_py36h3b971d6_104    conda-forge
hdf5                      1.10.6          nompi_he0bbb20_101    conda-forge
html5lib                  1.1                pyh9f0ad1d_0    conda-forge
icc_rt                    2019.0.0             h0cc432a_1
icu                       64.2                 he025d50_1    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
imagecodecs-lite          2019.12.3        py36h7725771_1    conda-forge
imageio                   2.9.0                      py_0    conda-forge
importlib-metadata        1.7.0            py36h9f0ad1d_0    conda-forge
importlib_metadata        1.7.0                         0    conda-forge
intel-openmp              2019.4                      245
ipykernel                 5.3.4            py36h5ca1d4c_0    conda-forge
ipympl                    0.5.7              pyh9f0ad1d_1    conda-forge
ipython                   7.16.1           py36h95af2a2_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.5.1                      py_0    conda-forge
isort                     4.3.21           py36h9f0ad1d_1    conda-forge
jedi                      0.17.2           py36h9f0ad1d_0    conda-forge
jinja2                    2.11.2             pyh9f0ad1d_0    conda-forge
jpeg                      9d                   he774522_0    conda-forge
json5                     0.9.4              pyh9f0ad1d_0    conda-forge
jsonschema                3.2.0            py36h9f0ad1d_1    conda-forge
jupyter_client            6.1.6                      py_0    conda-forge
jupyter_core              4.6.3            py36h9f0ad1d_1    conda-forge
jupyterlab                2.2.2                      py_0    conda-forge
jupyterlab_server         1.2.0                      py_0    conda-forge
kiwisolver                1.2.0            py36h246c5b5_0    conda-forge
lazy-object-proxy         1.4.3            py36h68a101e_2    conda-forge
libblas                   3.8.0                    14_mkl    conda-forge
libcblas                  3.8.0                    14_mkl    conda-forge
libclang                  9.0.1           default_hf44288c_0    conda-forge
libiconv                  1.15              hfa6e2cd_1006    conda-forge
liblapack                 3.8.0                    14_mkl    conda-forge
libpng                    1.6.37               hfe6a214_1    conda-forge
libsodium                 1.0.17               h2fa13f4_0    conda-forge
libtiff                   4.1.0                h885aae3_6    conda-forge
libxml2                   2.9.10               h5d81f1c_2    conda-forge
libxslt                   1.1.33               h579f668_1    conda-forge
lxml                      4.5.2            py36hd9844f4_0    conda-forge
lz4-c                     1.9.2                h62dcd97_1    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6
m2w64-gcc-libs            5.3.0                         7
m2w64-gcc-libs-core       5.3.0                         7
m2w64-gmp                 6.1.0                         2
m2w64-libwinpthread-git   5.0.0.4634.697f757               2
markupsafe                1.1.1            py36h68a101e_1    conda-forge
matplotlib                3.3.0                         1    conda-forge
matplotlib-base           3.3.0            py36h856a30b_1    conda-forge
matplotlib-scalebar       0.6.2                    pypi_0    pypi
mccabe                    0.6.1                      py_1    conda-forge
mistune                   0.8.4           py36h68a101e_1001    conda-forge
mkl                       2019.4                      245
mkl-service               2.3.0            py36hfa6e2cd_0    conda-forge
mpmath                    1.1.0                      py_0    conda-forge
msys2-conda-epoch         20160418                      1
nb_conda_kernels          2.2.3                    py36_0    conda-forge
nbconvert                 5.6.1            py36h9f0ad1d_1    conda-forge
nbdime                    2.0.0                      py_1    conda-forge
nbformat                  5.0.7                      py_0    conda-forge
networkx                  2.4                        py_1    conda-forge
nodejs                    14.7.0                        0    conda-forge
notebook                  6.0.3            py36h9f0ad1d_1    conda-forge
numpy                     1.19.1           py36h4d86e3b_0    conda-forge
olefile                   0.46                       py_0    conda-forge
openssl                   1.1.1g               he774522_1    conda-forge
packaging                 20.4               pyh9f0ad1d_0    conda-forge
pandas                    1.1.0            py36h003fed8_0    conda-forge
pandoc                    2.10.1               he774522_0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.7.1              pyh9f0ad1d_0    conda-forge
pathlib                   1.0.1            py36h9f0ad1d_2    conda-forge
pickleshare               0.7.5           py36h9f0ad1d_1001    conda-forge
pillow                    7.2.0            py36he4e95fe_1    conda-forge
pip                       20.2                       py_0    conda-forge
prometheus_client         0.8.0              pyh9f0ad1d_0    conda-forge
prompt-toolkit            3.0.5                      py_1    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pygments                  2.6.1                      py_0    conda-forge
pylint                    2.5.3            py36h9f0ad1d_0    conda-forge
pyopenssl                 19.1.0                     py_1    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyqt                      5.12.3           py36h003fed8_3    conda-forge
pyqt5-sip                 4.19.18                  pypi_0    pypi
pyqtchart                 5.12                     pypi_0    pypi
pyqtwebengine             5.12.1                   pypi_0    pypi
pyreadline                2.1                   py36_1001    conda-forge
pyrsistent                0.16.0           py36h68a101e_0    conda-forge
pysocks                   1.7.1            py36h9f0ad1d_1    conda-forge
python                    3.6.10          he025d50_1009_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.6                     1_cp36m    conda-forge
pytz                      2020.1             pyh9f0ad1d_0    conda-forge
pyvisa                    1.10.1           py36h9f0ad1d_3    conda-forge
pywavelets                1.1.1            py36h7725771_1    conda-forge
pywin32                   227              py36hfa6e2cd_0    conda-forge
pywinpty                  0.5.7                    py36_0    conda-forge
pyyaml                    5.3.1            py36h68a101e_0    conda-forge
pyzmq                     19.0.1           py36h274d426_0    conda-forge
qt                        5.12.5               h7ef1ec2_0    conda-forge
requests                  2.24.0             pyh9f0ad1d_0    conda-forge
scikit-image              0.17.2           py36hcc50265_1    conda-forge
scikit-rf                 0.15.3             pyh9f0ad1d_0    conda-forge
scipy                     1.5.0            py36h9439919_0
send2trash                1.5.0                      py_0    conda-forge
setuptools                49.2.0           py36h9f0ad1d_0    conda-forge
six                       1.15.0             pyh9f0ad1d_0    conda-forge
smmap                     3.0.4              pyh9f0ad1d_0    conda-forge
soupsieve                 2.0.1            py36h9f0ad1d_0    conda-forge
sqlite                    3.32.3               he774522_1    conda-forge
sympy                     1.6.1            py36h9f0ad1d_0    conda-forge
tabulate                  0.8.7              pyh9f0ad1d_0    conda-forge
terminado                 0.8.3            py36h9f0ad1d_1    conda-forge
testpath                  0.4.4                      py_0    conda-forge
tifffile                  2019.7.26.2              py36_0    conda-forge
tk                        8.6.10               hfa6e2cd_0    conda-forge
toml                      0.10.1             pyh9f0ad1d_0    conda-forge
toolz                     0.10.0                     py_0    conda-forge
tornado                   6.0.4            py36hfa6e2cd_0    conda-forge
tqdm                      4.48.0             pyh9f0ad1d_0    conda-forge
traitlets                 4.3.3            py36h9f0ad1d_1    conda-forge
typed-ast                 1.4.1            py36hfa6e2cd_0    conda-forge
typing_extensions         3.7.4.2                    py_0    conda-forge
urllib3                   1.25.10                    py_0    conda-forge
vc                        14.1                 h869be7e_1    conda-forge
vega_datasets             0.8.0                      py_0    conda-forge
vs2015_runtime            14.16.27012          h30e32a0_2    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_1    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.34.2                     py_1    conda-forge
widgetsnbextension        3.5.1            py36h9f0ad1d_1    conda-forge
win_inet_pton             1.1.0                    py36_0    conda-forge
wincertstore              0.2                   py36_1003    conda-forge
winpty                    0.4.3                         4    conda-forge
wrapt                     1.11.2           py36h68a101e_0    conda-forge
xz                        5.2.5                h62dcd97_1    conda-forge
yaml                      0.2.5                he774522_0    conda-forge
zeromq                    4.3.2                ha925a31_3    conda-forge
zipp                      3.1.0                      py_0    conda-forge
zlib                      1.2.11            h2fa13f4_1006    conda-forge
zstd                      1.4.5                h1f3a1b7_2    conda-forge
scimax commented 4 years ago

I think this is fixed with mpl 3.2.1

So while mpl 3.3.0 introduced another different exception, mpl 3.2.2. also works.