How to suppress matplotlib inline for a single cell in Jupyter Notebooks/Lab?
Asked Answered
E

1

7

I was looking at matplotlib python inline on/off and this kind of solves the problem but when I do plt.ion() all of the Figures pop up (100s of figures). I want to keep them suppressed in a single cell. Is there a with loop I can use to turn off %matplotlib inline or is this impossible?

Excurvature answered 28/3, 2018 at 22:11 Comment(7)
What exactly is the problem? Why would you use plt.ion() in a jupyter cell? To suppress any output from a jupyter cell use %%capture as the first line of that cell. Is that what you mean?Manganate
%%capture can suppress all output from a Jupyter cell? I didn't know that. I will take another look at the magic lines. Thank you. That will be a good fix for what I'm looking for atm. Ideally, I would only want to turn off the plotting because I usually write to stdout at certain checkpoints but I could do without that in the meantime. Ideally I would want something like with %matplotlib inline == False: [code]. However, I realize that I completely butchered the syntax for the with statement, the magic, and the use of a boolean but I'm not sure if there's something similar.Excurvature
There is this question also, which shows possible solutions. But I have to admit that none except %%capture ever worked for me (hence my answer there).Manganate
I added another answer to the linked question. Should we mark this as duplicate? Given that there is no such thing as without inline do:? Else you should probably clearly state in how far this question is different from the other one, explaining why none of the four solutions are not working for you.Manganate
Maybe this one should be flagged as duplicate if %%capture was the only approach that worked for you. Thanks!Excurvature
Well, as pointed out in the newly added answer, %matplotlib agg would work as well. Did you try that?Manganate
I had a similar issue (???), I made a context manager to disable plotting in IPython, maybe it helps? See my question; #52116396Taxicab
H
4

Figures closed before the end of the cell will not be shown. Calling plt.close("all") at the end of the cell will close all figures and none will be displayed in the cell's output.

Hatred answered 19/2, 2020 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.