1

Question

In Jupyter notebook, is it possible to turn off the interactive mode on a figure? The ax.plot() does not show a line when running from the command line python but in a Jupyter notebook cell, it shows up.

import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(7,5))
plt.ioff()
ax.plot([1.6, 2.7])     # <--- Still the line shows up in a jupyter notebook

...

plt.ion()
plt.draw()
plt.show()

Version

$ jupyter notebook --version
6.2.0

from platform import python_version
print(python_version())

3.8.8

Related

matplotlib python inline on/off suggests using %matplotlib but not sure why using the magic command to turn on/off the interactive mode.

It also has a mention below but not sure what it exactly means.

on and ioff set interactive mode, determining if the plot is updated after each plotting command (interactive mode on) or it waits plt.show() (if interactive mode is off). This is independent on inline, that decides if the notebook or the console should display the graphics (this happens any time the plot is updated, meaning at every plotting command if interactive mode is set with ion, or after plt.plot if unset with ioff).

mon
  • 18,789
  • 22
  • 112
  • 205
  • hi, interesting, perhaps this might have the answer https://stackoverflow.com/questions/41316370/programmatically-stop-interaction-for-specific-figure-in-jupyter-notebook – IronMan Mar 13 '21 at 00:46
  • "but in a Jupyter notebook cell, it shows up." Is your question about showing vs not showing the figure in the output cell? Or, as the title suggests, is it about showing the figure in the interactive mode (with zoom/pan tools) vs showing the figure in the non-interactive mode (currently the default in Jupyter Notebook)? – Patrick FitzGerald Mar 13 '21 at 09:46
  • Hello @PatrickFitzGerald, the goal is not to show the plot line until the plot.show() is called. I like to control the timing when to show. – mon Mar 14 '21 at 04:52
  • Ok. And are `ax.plot` and `plt.show` in separate input cells? In any case, I think it could be worth considering to edit the title of the question to better reflect the problem you are facing, seeing as it is about showing vs not showing the plot rather than showing the plot in interactive mode (with pan/zoom tools) [vs showing the plot as a static image](https://i.stack.imgur.com/dAY7x.png). – Patrick FitzGerald Mar 14 '21 at 09:48

1 Answers1

0

Quibbler might be of some help here: https://github.com/Technion-Kishony-lab/quibbler

It helps create interactive graphics in matplotlib.

for transparency: I am one of the developers of Quibbler.

royk
  • 85
  • 7