zoukankan      html  css  js  c++  java
  • 服务器上使用matplotlib.pyplot绘图

    在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
  • 相关阅读:
    接口测试工具postman学习
    接口测试工具jmeter压力测试
    WSGI规范
    ADB命令详解
    eclipse导入远端git
    os.system、os.popen和subprocess.popen的区别
    获取Android当前运行最顶层的activity
    python+appuim 处理系统权限弹窗
    Appium之xpath定位元素
    Charles配置抓取HTTPS请求的Android配置
  • 原文地址:https://www.cnblogs.com/congyucn/p/8442472.html
Copyright © 2011-2022 走看看