matplotlib和pylab情节问题

时间:2015-09-16 22:29:26

标签: python-2.7 matplotlib

我尝试在centos 7机器上编译matplotlib 1.4.2和pylab,并尝试运行以下程序:

#!/bin/python

import numpy as np
import matplotlib
import pylab as pl


X = np.linspace(-np.pi, np.pi,256,endpoint=True)
C = np.cos(X)

pl.plot(X,C)

当我运行此程序时,我收到以下错误消息:

Traceback (most recent call last):
  File "check.py", line 11, in <module>
    pl.plot(X,C)
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-    x86_64.egg/matplotlib/pyplot.py", line 3092, in plot
    ax = gca()
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-    x86_64.egg/matplotlib/pyplot.py", line 828, in gca
    ax =  gcf().gca(**kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-  x86_64.egg/matplotlib/pyplot.py", line 462, in gcf
    return figure()
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 435, in figure
**kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-  x86_64.egg/matplotlib/backends/backend_qt4agg.py", line 47, in      new_figure_manager
    return new_figure_manager_given_figure(num, thisFig)
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-x86_64.egg/matplotlib/backends/backend_qt4agg.py", line 54, in   new_figure_manager_given_figure
    canvas = FigureCanvasQTAgg(figure)
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-   x86_64.egg/matplotlib/backends/backend_qt4agg.py", line 72, in __init__
    FigureCanvasQT.__init__(self, figure)
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-x86_64.egg/matplotlib/backends/backend_qt4.py", line 68, in __init__
_create_qApp()
  File "/usr/lib64/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-x86_64.egg/matplotlib/backends/backend_qt5.py", line 138, in _create_qApp
    raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

知道可能导致这些错误的原因吗?如何用matplot lib 1.4.2生成图?我确实回显了变量$ DISPLAY,没有出现任何内容。我该如何解决这个问题?

感谢您的时间。

0 个答案:

没有答案