linux 使用 Python 画图工具matplotlib 提示display 错误

Posted lph970417

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 使用 Python 画图工具matplotlib 提示display 错误相关的知识,希望对你有一定的参考价值。

import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 97, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
    globals(),locals(),[backend_name])
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 13, in <module>
    import gtk; gdk = gtk.gdk
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
    _init()
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
    _gtk.init_check()
RuntimeError: could not open display

使用一下命令

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

成功画图

以上是关于linux 使用 Python 画图工具matplotlib 提示display 错误的主要内容,如果未能解决你的问题,请参考以下文章

python使用graphviz工具画图

解决seaborn画图无法显示中文的问题

Python海龟画图工具绘制叮当猫程序

Python超简单容易上手的画图工具库

python画图的问题~

Linux Centos7安装配置画图工具Graphviz