matplotlib / ipympl

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

matplotlib widget occasionally fails to render. #231

Open pulkin opened 4 years ago

pulkin commented 4 years ago

Bug report

Bug summary

Matplotlib widget occasionally fails to render.

Code for reproduction

%matplotlib widget
from matplotlib import pyplot
fig, axes = pyplot.subplots(1, 2, figsize=(8, 4))
pyplot.show()
raise

Actual outcome

Screenshot

Expected outcome

Two empty subplots.

Matplotlib version

tacaswell commented 4 years ago

If in the next cell you do fig.canvas and let jupyter repr that do you get a live figure? My suspicion is that some part of the ipywidgets setup that links the JS to the kernel is set up as part of the code that is run by jupyter when a cell is done successfully and not done as part of the code that runs when a cell fails.

pulkin commented 4 years ago

If in the next cell you do fig.canvas and let jupyter repr that do you get a live figure?

fig.canvas in the subsequent cell renders exactly as the above.

tacaswell commented 4 years ago

I think this mostly on the widget side of the house, moved to ipympl.

martinRenou commented 4 years ago

Do you get an error in the JavaScript console? https://webmasters.stackexchange.com/questions/8525/how-do-i-open-the-javascript-console-in-different-browsers

pulkin commented 4 years ago

There is nothing I could associate with the issue. Also, nothing is output when I try to reproduce the issue by pressing ctrl-enter.

asteppke commented 4 years ago

Another connected outcome of this issue: When restarting and running a longer notebook from top to bottom all figures do not show up if the execution ends with an exception:

image

This means you have to manually executes cells step by step so that you never run a cell together with another cell that raises an exception later.

This happens reproducibly here with the current ipympl 0.5.6 but also with earlier versions.