matplotlib图在Anaconda for Linux上没有显示

时间:2014-05-25 19:46:32

标签: python-2.7 matplotlib ubuntu-12.04

我已经阅读了这些并尝试了解决方案,但仍然无法显示任何内容:

matplotlib show nothing although i called show

Why doesn't pyplot.show() work? [duplicate]

matplotlib does not show my drawings although I call pyplot.show()

我在Ubuntu 12.04上使用Python 2.7.6 | Anaconda 1.9.0(64位)。 我该如何诊断问题并尝试解决?

编辑:

- 首先我编辑了matplotlibrc并将后端更改为GtkAgg(设置为QtAgg)。

- 然后我尝试通过代码更改后端:matplotlib.rcParams [' backend'] =" GtkAgg"

EDIT2 - 从Spyder控制台添加细节(最后没有显示情节):

Python 2.7.6 |Anaconda 1.9.0 (64-bit)| (default, Jan 17 2014, 10:13:17) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Imported NumPy 1.8.0, SciPy 0.13.3, Matplotlib 1.3.1
Type "scientific" for more details.
>>> scientific

This is a standard Python interpreter with preloaded tools for scientific 
computing and visualization. It tries to import the following modules:

>>> import numpy as np  # NumPy (multidimensional arrays, linear algebra, ...)
>>> import scipy as sp  # SciPy (signal and image processing library)
>>> import matplotlib as mpl         # Matplotlib (2D/3D plotting library)
>>> import matplotlib.pyplot as plt  # Matplotlib's pyplot: MATLAB-like syntax
>>> from pylab import *              # Matplotlib's pylab interface
>>> ion()                            # Turned on Matplotlib's interactive mode

Within Spyder, this interpreter also provides:
    * special commands (e.g. %ls, %pwd, %clear)
    * system commands, i.e. all commands starting with '!' are subprocessed
      (e.g. !dir on Windows or !ls on Linux, and so on)

>>> plot(range(3))
[<matplotlib.lines.Line2D object at 0x3f3cd50>]
>>> show()

3 个答案:

答案 0 :(得分:2)

为了使matplotlib后端选择起作用,您需要安装该后端的Python绑定。例如,您可能正在运行基于GTK的Windows管理器,例如GNOME,但仍然没有Python绑定。根据{{​​3}},正确的Ubuntu包是python-gtk。因此,打开您最喜欢的终端模拟器并输入

sudo apt-get install python-gtk

(您需要管理员权限才能执行此操作)。重启你的python / matplotlib会话,你应该好好去。

答案 1 :(得分:2)

我最终在Spyder中做到这一点: 偏好 - &gt;控制台 - &gt;外部模块 - &gt;检查为Qt安装Spyder的输入挂钩

答案 2 :(得分:0)

我在小牛队,通过在matplotlibrc中将后端更改为Qt4Agg来解决问题。 (按照另一个答案的说明:Why doesn't pyplot.show() work?