-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%matplotlib ipympl does not allow cell "re-plot" ? #248
Comments
Hi @Mike-HubGit the behavior you describe is definitely confusing but I believe it is actually expected. Whenever a new figure is created in a cell it is automatically displayed (see updated example in #244) you can see this is if you call 1: 2: 3: Cell 1: fig = plt.figure()
plt.plot([1,2,3]) Cell 2: display(fig)
display(fig.canvas) I would expect the outputs to be:
Cell 2:
hope this is helpful, feel free to ask more questions as this can definitely be a bit mystifying |
Thanks for your comments. However :
Thanks a lot, |
I normally just stick |
I believed the developpers made a limit to 20 for reasons of limited resources ? |
I often do the following: plt.close('some-fig-name')
plt.figure('some-fig-name')
# do whatever plotting you want or i suppose you could do: fig = plt.figure('some-fig-name')
fig.cla()
# do whatever plotting you want
The rationale for adding it is here: matplotlib/matplotlib#1919 (comment) and part of the quote is: "This could be an RC parameter so that users who do want to open 1000 figures (and have the RAM for it) can." so if you do in fact have the ram you should be able so set it to whatever you want. Also that limit was added in 2013 and I suppose that what a standard amount of ram is has increased so you probably have some wiggle room.
How do you mean by "invoking 'fig'"? whenever you |
I am not clear on how you would effectively use more than ~20 figures. With |
@tacaswell : On my configuration based on Jupyter 1.3.2, if I plot a single figure in a cell and that I run it many times I reach the 20 figures limit. This is a classical process as I change elements of the cell to reach the result that I want. |
@ianhi : plt.close('some-fig-name')
plt.figure('some-fig-name')
# do whatever plotting you want Is actually what I do. However it is weird to close a figure that has never been opened. In fact : I would like to use this great environment with my students, and I search some clean message to give to them. If some behaviours are weird to me, they will be for them to, and it is a bad message about the computer as a tool for scientific work. When I invoke "display", in most cases I obtain a widget, but sometimes a png, and sometimes both (!!) depending on in what order I write the commands. |
I think this is a bug in ipympl that it is leaking the invisible, but still open figures. The use you described should work. The workarounds that @ianhi suggests above are both reasonable if a bit verbose. The core of the issue here is that the conventions of Matplotlib (which long pre-dates jupyter) have some assumptions that the interactive figures are GUI windows baked in. To "show" a GUI window you tell the tool kit to show it, it defers to the underlying window manager, and the user sees it. When the user close the window we have un-ambigious hooks that that has happened and delete the figure from the pyplot state. This is a bit messier in the notebook as adding / removing to the DOM are more complex than popping a window up. There is also the convention that the last thing in a cell gets auto-displayed so if you explicitly say "show this figure", it gets added to the DOM and then it also happens to be the last thing in the cell so it also gets displayed. There is some effort at doing effectively "display refernce" counting to try to suppress that, but if you are seeing two copies then it is not being suppressed enough. There is also the issue that rich repr of the |
@tacaswell : I understand. However : the "notebook" mode if jupyter (without lab) worked well and I do not remember the problems you mention. |
@Mike-HubGit are you running the cell multiple times to adjust parameters of the lines you are plotting, or in order to adjust styling and such? If you are aiming for the former usecase then I'd recommend using the sliders provided by ipywidgets to continuously update the lines as you tune the parameters by hand.
I think this is a longstanding issue, and unfortunately a tricky one to solve. See: #4 Also this issue of the figure warning has also been discussed here: #64 |
@ianhi : for many reasons ! debugging, parameters, styling. |
Describe the issue
Starting from a fresh notebook/python3 in JupyterLab 2.1.5, with 2 cells [1] and [2] :
[1] :
[2] :
If I run [1] then [2], okay I see the plot.
If I run again [2], I obtain :
and cannot see the plot.
But if I update [2] like :
[2] :
Then I see the plot again. Weird as it does not work like this with %matplotlib inline or with %matplotlib notebook with Jupiter (not Lab).
Another thing surprizing, adding a "figure" :
[1] :
[2] :
[3] :
Displays a png picture of the plot at the level of cell [3] ...
Versions
The text was updated successfully, but these errors were encountered: