码迷,mamicode.com
首页 > 其他好文 > 详细

服务器上使用matplotlib.pyplot绘图

时间:2018-02-11 18:12:28      阅读:1869      评论:0      收藏:0      [点我收藏+]

标签:ann   style   back   ast   from   not   rom   call   导入   

在linux服务器端执行python脚本,有时候需要画图,但是linux没有GUI界面,因此需要在导入matplotlib.pyplot库之前先执行

import matplotlib as mpl
mpl.use(Agg)

再执行

import matplotlib.pyplot as plt

需要保存图片到指定的目录

plt.savefig("/home/yourname/test.jpg") 

直接执行 import matplotlib.pyplot as plt 会报错:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 116, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
    [backend_name], 0)
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
    from .backend_qt5 import (
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 18, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 56, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "/root/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py", line 137, in <module>
    from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

 

服务器上使用matplotlib.pyplot绘图

标签:ann   style   back   ast   from   not   rom   call   导入   

原文地址:https://www.cnblogs.com/CongYuUestcer/p/8442472.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!