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
I have happily used interactive plots in jupyter notebooks for years with %matplotlib notebook. Unfortunately, since version 7 was introduced, I have experienced troubles with getting interactive plotting to work properly. I read that version 7 requires installing ipympl and %matplotlib ipympl.
Today, I set up a fresh virtual environment and installed jupyter and ipympl. Figures are opening, the controls appear, a figure title appears, but the figure contains no content. There is also no error message on the browser's developer console.
A white area is opening, the controls appear, but there is no figure content.
I have seen several similar issues on Stackoverflow, where the solution is usually to upgrade or downgrade one of the packages. However, these answers have aged as newer versions came out in the meantime. Is there a general recipe to identify the issue when interactive plotting fails?
Thanks, I updated my initial post with the list of extensions. As far as I can see, the versions should be compatible according to the version compatibility table.
I wonder if this has to do with ipympl not supporting plt.subplot (it is). Friendly ping @ianhi, I suspect you're more familiar than me on this matter.
Wait, I see something really weird (same code, same environment, same server, different notebooks, on the left I can see the plot 100% of the time when executing, on the right I never see it):
It seems we have some kind of race condition in the initialization of the plot in the case of Notebook 7. It was never reported in the case of JupyterLab AFAIK.
I downgraded to jupyterlab 4.2.3 to see if that helped based on @ianhi's comment, but it's still present.
It is worth noting that in chromium, I do see the plots, but the javascript console has errors on both browsers.
It is also worth noting that it seems to reproduce without subplots being involved at all?
Unfortunately I've been unable to replicate this with jupyterlab 4.2.3 (or the notebook command). What browser are you using? I'm on firefox
It seems to me that it's random, some kind of race condition. I wonder if simulating a slow connection using the dev tools would help us replicate the issue more easily.
For what it's worth - it does not seem random on my machine. It reproduces reliably in Firefox, both with a local and remote jupyterlab environment. As in, I haven't yet seen it not reproduce!
Or - if it /is/ random, my luck is clearly terrible!
Creating a new notebook and then trying to use ipympl results in a blank plot, but the widgets display.
If I close the browser tab and then reopen, the plot now displays but is inactive: it won't interact with the mouse.
Closing the tab and killing the server, then restarting, results in interactive plots working. I can now add new plots etc. and everything works as I expect.
Re-created consistently in Firefox and Edge, on Windows 10.
I tried to look into this today, I also don't think it's a race condition as it's reliably reproducible as described in #556 (comment).
As mentioned, it happens when a new notebook is created, but if the notebook is later opened again after restarting the server, it doesn't happen anymore. So it has something to do with how the plots are initialized from a previously saved notebook.
I don't know much about Jupyter extension development but I found that the refresh message below is sent (or the handle_resize function called) only in the working case. So when creating a new notebook, either handle_resize is not properly registered or the resize message is not sent.
The problem seems to be related specifically to the behavior of the "New -> Python 3 (ipykernel)" button in the Jupyter UI. If I create a new notebook via that button, the issue appears. But if I create a new notebook by going to my file browser and copy-pasting a blank notebook with identical contents to the one created from the UI (while the server is running), and open that, it works OK.
Just a quick note to say that I see this issue in VS Code as well - if I create and run a notebook, save it, close it, then open it again (potentially after a VS Code restart as well), the plots don't show but show an error message.
You can force a figure to be re drawn with figure.canvas.draw(), or plt.draw(), which I have used before but now that I'm testing it it's not working... #290 might be related. Sadly it doesn't seem to help with this issue.
I too can confirm the issue. However, the following workaround of mine could perhaps shed some light.
A reliable workaround for my case is to execute the same cell twice quickly (a key-mouse combo: "shift+enter" + "mouse left click the same cell" + "shift+enter"). The second execution usually resulted in the image being properly shown.
I believe I have been seeing the same (or at least a related) problem. Figures appear, have controls, but no actual content in the plot. For me this would happen maybe 80% of the time, seemingly randomly, and I would often just keep running the cell over and over until the plot would appear. But I finally found a workaround that so far is 100% successful. In my case, it seems that I needed to move tight_layout to the very end of the code, and also precede it with a short plt.pause(). (Removing tight_layout also worked...)
plt.pause(0.05) # helps tight_layout work
plt.tight_layout()
For what it's worth, I've had problems with blank figures, missing figures, sliders but no figures, bizarrely misrendered figures (not even with tight_layout().
But, using @AdamCBartnik 's suggestion of adding plt.pause(0.05) worked for some reason.
Can't figure out why though.
Activity
martinRenou commentedon Jun 5, 2024
Thanks for opening an issue.
So it looks like ipympl was properly installed and is working with Notebook 7, otherwise you wouldn't see the figure controls.
It's weird though that you are getting a white area. I will try to reproduce.
btlorch commentedon Jun 5, 2024
Thanks, I updated my initial post with the list of extensions. As far as I can see, the versions should be compatible according to the version compatibility table.
martinRenou commentedon Jun 5, 2024
Yes, your installation looks perfectly fine.
What is your matplotlib version?
btlorch commentedon Jun 5, 2024
My matplotlib version is 3.9.0.
martinRenou commentedon Jun 5, 2024
Thanks, I can reproduce your issue.
I wonder if this has to do with ipympl not supporting(it is). Friendly ping @ianhi, I suspect you're more familiar than me on this matter.plt.subplotmartinRenou commentedon Jun 5, 2024
Wait, I see something really weird (same code, same environment, same server, different notebooks, on the left I can see the plot 100% of the time when executing, on the right I never see it):
btlorch commentedon Jun 5, 2024
Hm, I shut down and close the notebook, then reopen it, I can see the figure.
When I create another new notebook, there the figure does not show up.
martinRenou commentedon Jun 5, 2024
It seems we have some kind of race condition in the initialization of the plot in the case of Notebook 7. It was never reported in the case of JupyterLab AFAIK.
jtpio commentedon Jun 12, 2024
For reference this seems to be the case in JupyterLab 4.2.2 too:
ianhi commentedon Jul 8, 2024
Sorry all, i've been off github and literally in the lab basement getting the final datasets I need in order finsih grad school.
Unfortunately I've been unable to replicate this with jupyterlab 4.2.3 (or the
notebookcommand). What browser are you using? I'm on firefoxtoygardarm commentedon Aug 21, 2024
Hi!
I'm also running into this.
I downgraded to jupyterlab 4.2.3 to see if that helped based on @ianhi's comment, but it's still present.
It is worth noting that in chromium, I do see the plots, but the javascript console has errors on both browsers.
It is also worth noting that it seems to reproduce without subplots being involved at all?
Firefox:
chromium:
martinRenou commentedon Aug 21, 2024
It seems to me that it's random, some kind of race condition. I wonder if simulating a slow connection using the dev tools would help us replicate the issue more easily.
toygardarm commentedon Aug 21, 2024
For what it's worth - it does not seem random on my machine. It reproduces reliably in Firefox, both with a local and remote jupyterlab environment. As in, I haven't yet seen it not reproduce!
Or - if it /is/ random, my luck is clearly terrible!
MatthewDaws commentedon Feb 6, 2025
For what it's worth, I am having exactly the same problem.
ipymplresults in a blank plot, but the widgets display.juhaszp95 commentedon Apr 17, 2025
I wonder if it's related to this issue?
mgunyho commentedon Jun 27, 2025
I tried to look into this today, I also don't think it's a race condition as it's reliably reproducible as described in #556 (comment).
As mentioned, it happens when a new notebook is created, but if the notebook is later opened again after restarting the server, it doesn't happen anymore. So it has something to do with how the plots are initialized from a previously saved notebook.
I don't know much about Jupyter extension development but I found that the
refreshmessage below is sent (or thehandle_resizefunction called) only in the working case. So when creating a new notebook, eitherhandle_resizeis not properly registered or the resize message is not sent.ipympl/src/mpl_widget.ts
Line 170 in 5e068ed
mgunyho commentedon Jun 27, 2025
The problem seems to be related specifically to the behavior of the "New -> Python 3 (ipykernel)" button in the Jupyter UI. If I create a new notebook via that button, the issue appears. But if I create a new notebook by going to my file browser and copy-pasting a blank notebook with identical contents to the one created from the UI (while the server is running), and open that, it works OK.
juhaszp95 commentedon Jun 27, 2025
Just a quick note to say that I see this issue in VS Code as well - if I create and run a notebook, save it, close it, then open it again (potentially after a VS Code restart as well), the plots don't show but show an error message.
tavin commentedon Jun 29, 2025
I have a notebook with multiple cells, each showing a blank figure, until the last cell finishes and the kernel stops. Then they all appear.
mgunyho commentedon Jun 29, 2025
You can force a figure to be re drawn with
figure.canvas.draw(), orplt.draw(), which I have used before but now that I'm testing it it's not working... #290 might be related. Sadly it doesn't seem to help with this issue.nvaytet commentedon Nov 11, 2025
Does anyone see the figure appear if you try to resize the figure by dragging the lower-right corner handle?
hyliu1989 commentedon Nov 13, 2025
I too can confirm the issue. However, the following workaround of mine could perhaps shed some light.
A reliable workaround for my case is to execute the same cell twice quickly (a key-mouse combo: "shift+enter" + "mouse left click the same cell" + "shift+enter"). The second execution usually resulted in the image being properly shown.
A reference codes is
where image2 and image3 are numpy arrays of shape (1500, 4000).
AdamCBartnik commentedon Mar 24, 2026
I believe I have been seeing the same (or at least a related) problem. Figures appear, have controls, but no actual content in the plot. For me this would happen maybe 80% of the time, seemingly randomly, and I would often just keep running the cell over and over until the plot would appear. But I finally found a workaround that so far is 100% successful. In my case, it seems that I needed to move tight_layout to the very end of the code, and also precede it with a short plt.pause(). (Removing tight_layout also worked...)
jbphyswx commentedon Apr 12, 2026
For what it's worth, I've had problems with blank figures, missing figures, sliders but no figures, bizarrely misrendered figures (not even with
tight_layout().But, using @AdamCBartnik 's suggestion of adding
plt.pause(0.05)worked for some reason.Can't figure out why though.