What happens when you call IPython with the command line argument `--matplotlib`?
I could only find this in the help section.
Configure matplotlib for interactive use with default matplotlib
I was having performance issues using matplotlib.pyplot with the IPython command line until I tried the option --matplotlib
.
Example
Without --matplotlib
$ ipython
In [1]: import matplotlib as mpl
In [2]: import matplotlib.pyplot as plt
In [3]: mpl.get_backend()
Out[3]: u'Qt4Agg'
In [4]: plt.plot([0, 1, 2], [0, 1, 2])
Out[4]: [<matplotlib.lines.Line2D at 0xb473198>]
# IPython command-line becomes entirely unresponsive, must restart IPython to become usable again
FROM --matplotlib
$ ipython --matplotlib
In [1]: import matplotlib as mpl
In [2]: import matplotlib.pyplot as plt
In [3]: mpl.get_backend()
Out[3]: u'Qt4Agg'
In [4]: plt.plot([0, 1, 2], [0, 1, 2])
Out[4]: [<matplotlib.lines.Line2D at 0xcbe1d68>]
# IPython command-line remains responsive
I suspect the side effect of using the argument --matplotlib
improves performance, but I would like to know how.
Customization
- IPython: 3.0.0
- matplotlib: 1.4.3
- Python: 2.7.9 :: Anaconda 2.2.0 (64-bit)
- Windows 7 (64-bit)
source to share
I think this is the equivalent of setting plt.interactive(True)
(i.e. enabling interactive mode or equivalent launch plt.ion()
), so that when the shape is instantiated, you still have control over the terminal. See here for details .
For example:
$ ipython --matplotlib
import matplotlib.pyplot as plt
plt.isinteractive()
# True
Unlike:
$ ipython
import matplotlib.pyplot as plt
plt.isinteractive()
# False
As a basic note, in the first example, the command line will remain unresponsive until you close the shape that your command created plt.plot
. When you close this window, you should regain control of the command line.
source to share