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
  • 相关阅读:
    POJ3421(质因数分解)
    POJ2236(并查集入门)
    POJ3111(最大化平均值)
    POJ2976(最大化平均值)
    POJ3104(二分搜索)
    POJ3258(最大化最小值)
    POJ2456(最大化最小值)
    POJ1063Cable master(二分搜索)
    Numpy模块(一)
    Django简介
  • 原文地址:https://www.cnblogs.com/congyucn/p/8442472.html
Copyright © 2011-2022 走看看