我是matplotlib的新用户,我的平台是Ubuntu 10.04 Python 2.6.5
这是我的代码
import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt plt.plot([1,2,3])
错误是:
/usr/local/lib/python2.6/dist-packages/matplotlib/backends/__init__.py:41: UserWarning: Your currently selected backend, 'agg' does not support show(). Please select a GUI backend in your matplotlibrc file ('/usr/local/lib/python2.6/dist-packages/matplotlib/mpl-data/matplotlibrc') or with matplotlib.use() (backend, matplotlib.matplotlib_fname()))
apt-get install libagg
python-gtk2-dev
这是错误:
>>> matplotlib.use('GTK') >>> import matplotlib.pyplot as plt Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.6/dist-packages/matplotlib/pyplot.py", line 95, in <module> new_figure_manager, draw_if_interactive, show = pylab_setup() File "/usr/local/lib/python2.6/dist-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup globals(),locals(),[backend_name]) File "/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_gtk.py", line 28, in <module> from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK File "/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_gdk.py", line 29, in <module> from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array ImportError: No module named _backend_gdk
您当前选择的后端“ agg”不支持show()。
AGG后端用于写入文件,而不用于在窗口中呈现。请参阅matplotlib网站上的后端常见问题解答。
AGG
ImportError:没有名为_backend_gdk的模块
对于第二个错误,也许您的matplotlib发行版未使用GTK支持进行编译,或者您错过了PyGTK软件包。尝试安装它。
您是否在show()可以访问图形环境的终端或应用程序中调用该方法?
show()
按以下顺序尝试其他GUI后端:
TkAgg
WX
QTAgg
QT4Agg