pythonmatplotlibinteractive-mode

Exact semantics of Matplotlib's "interactive mode" (ion(), ioff())?


The documentation for the "interactive mode" in Matplotlib's pyplot reads:

The interactive property of the pyplot interface controls whether a figure canvas is drawn on every pyplot command. If interactive is False, then the figure state is updated on every plot command, but will only be drawn on explicit calls to draw(). When interactive is True, then every pyplot command triggers a draw.

This seems clear enough: when the interactive mode is on, one can do plot() without having to do draw(). However, doing draw() in the following code does not do anything:

from matplotlib import pyplot as pp

# Interactive mode is off by default

pp.plot([10, 20, 50])
pp.draw()

raw_input('Press enter...')  # No graph displayed?!!

(on Windows XP, Matplotlib 1.0.1).

Adding ion() at the beginning makes the figure(s) appear, while waiting for the user to type enter (which conveniently closes all the figures):

from matplotlib import pyplot as pp

ion()

pp.plot([10, 20, 50])  # No draw() is necessary

raw_input('Press enter...')  # The graph is interactive *and* the terminal responds to enter

Thus, it looks like ion() does more than just adding automatic graph updates after each plotting command, and I unfortunately can't find anything in the documentation. Another, more important problem with the latter program is that ion() makes all plot commands update the graph, which is time consuming when a single graph is updated multiple times.

So, is there a way of:


Solution

  • Here is the summary of an interesting discussion on this subject in the Matplotlib mailing list. The executive summary is:

    In the mean time, more information on the interactive and non-interactive modes can be found in a current branch of Matplotlib. A better documentation for draw(), show() and friends can also be found in the same branch.