Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when you call IPython with the `--matplotlib` command-line argument?

I could only find this from their help section.

Configure matplotlib for interactive use with the default matplotlib

I have been having performance issues plotting using matplotlib.pyplot with the IPython command-line until I tried the --matplotlib option.

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

With --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 a side-effect of using the --matplotlib argument is boosting my performance, but I'd like to know how.

Setup

  • IPython: 3.0.0
  • matplotlib: 1.4.3
  • Python: 2.7.9 :: Anaconda 2.2.0 (64-bit)
  • Windows 7 (64-bit)
like image 994
Alex Avatar asked Dec 10 '25 17:12

Alex


1 Answers

I think it is the equivalent of setting plt.interactive(True) (i.e. turning interactive mode on, or equivalently running plt.ion()), so that when a figure instance is created, you still have control of the terminal. See here for more information.

For example:

$ ipython --matplotlib

import matplotlib.pyplot as plt
plt.isinteractive() 
# True

As opposed to:

$ ipython

import matplotlib.pyplot as plt
plt.isinteractive() 
# False

As a side note, in your first example, the command line will remain unresponsive until you close the figure that is created by your plt.plot command. Once you close that window, you should regain control of the command line.

like image 55
tmdavison Avatar answered Dec 12 '25 05:12

tmdavison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!