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?

O.rka
  • 29,847
  • 68
  • 194
  • 309
  • 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? – ImportanceOfBeingErnest Mar 28 '18 at 22:17
  • `%%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. – O.rka Mar 28 '18 at 22:33
  • There is [this question](https://stackoverflow.com/questions/18717877/prevent-plot-from-showing-in-jupyter-notebook) also, which shows possible solutions. But I have to admit that none except `%%capture` ever worked for me (hence my answer there). – ImportanceOfBeingErnest Mar 28 '18 at 22:48
  • I added [another answer](https://stackoverflow.com/a/49545730/4124317) 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. – ImportanceOfBeingErnest Mar 28 '18 at 23:25
  • Maybe this one should be flagged as duplicate if `%%capture` was the only approach that worked for you. Thanks! – O.rka Mar 29 '18 at 00:50
  • Well, as pointed out in the newly added answer, `%matplotlib agg` would work as well. Did you try that? – ImportanceOfBeingErnest Mar 29 '18 at 01:22
  • I had a similar issue (???), I made a context manager to disable plotting in IPython, maybe it helps? See my question; https://stackoverflow.com/questions/52115896/can-i-prevent-spyder-from-displaying-inline-images-temporarily/52116123#52116123 – Marcus Jones Aug 31 '18 at 13:11

1 Answers1

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.

mrawlik
  • 51
  • 4