交叉图Ipython 5.0.0在终端

时间:2016-07-16 15:36:47

标签: linux matplotlib terminal ipython

我在终端中运行Ipthon,在linux中运行(不是一个jupyter笔记本)。

在Ipython 2.4.1中,以下命令打开一个弹出式交互式Tk 情节窗口:

(prodEnv)[kv@loowkv1 sandbox]$ ipython
IPython 2.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.


In [1]: 

In [1]: %matplotlib
Using matplotlib backend: TkAgg
In [2]: import matplotlib.pyplot as plt
In [3]: import numpy as np
In [4]: plt.ion()
In [5]: x = np.arange(0, 4*np.pi, 0.1)
In [6]: y = [np.sin(i) for i in x]
In [7]: plt.plot(x, y, 'g-', linewidth=1.5, markersize=4)
Out[7]: [<matplotlib.lines.Line2D at 0x7f5c8a8b6410>]

在Ipython 5.0.0中,当我使用相同的代码时:

(prodEnv)[kv@loowkv1 sandbox]$ ipython3
Python 3.4.1 (default, Nov  3 2014, 14:38:10) 
Type "copyright", "credits" or "license" for more information.

IPython 5.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %matplotlib
   ...: import matplotlib.pyplot as plt
   ...: import numpy as np
   ...: plt.ion()
   ...: x = np.arange(0, 4*np.pi, 0.1)
   ...: y = [np.sin(i) for i in x]
   ...: plt.plot(x, y, 'g-', linewidth=1.5, markersize=4)
   ...: 
Using matplotlib backend: agg
Out[1]: [<matplotlib.lines.Line2D at 0x7fe49ae9c208>]
什么也没出现。如何在Iptyhon 5.0.0中获得弹出的交互式绘图?

1 个答案:

答案 0 :(得分:1)

使用ipython使用TkAgg输出,即使用tk(python-tk)作为后端。

  

使用matplotlib后端:TkAgg

但是ipython3agg

  

使用matplotlib后端:agg

我尝试使用ipython3TkAgg后端,它正常工作ipython。 您可能需要安装python3-tk才能将TkAggmatplotlib

一起使用