使用`--matplotlib`命令行参数调用IPython会发生什么?

时间:2015-07-24 08:19:56

标签: python matplotlib ipython

我只能从他们的帮助部分找到这个。

  

使用默认的matplotlib

配置matplotlib以进行交互式使用

我一直在使用matplotlib.pyplot和IPython命令行绘制性能问题,直到我尝试--matplotlib选项。

示例

没有--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

使用--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

我怀疑使用--matplotlib参数的副作用是提高我的表现,但我想知道如何。

设置

  • IPython:3.0.0
  • matplotlib:1.4.3
  • Python:2.7.9 :: Anaconda 2.2.0(64位)
  • Windows 7(64位)

1 个答案:

答案 0 :(得分:1)

我认为它等同于设置plt.interactive(True)(即打开交互模式,或等效运行plt.ion()),这样在创建图形实例时,您仍然可以控制终端。有关详细信息,请参阅here

例如:

$ ipython --matplotlib

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

相反:

$ ipython

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

作为旁注,在第一个示例中,命令行将保持无响应,直到您关闭由plt.plot命令创建的数字。关闭该窗口后,应重新控制命令行。

相关问题