• 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
    

    成功画图

  • 相关阅读:
    临时文件服务器,配置共享文件夹
    封装扩展方法
    List.Insert
    VS 生成事件中xcopy失败
    创建型设计模式总结
    js提交图片转换为base64
    C#建造者模式
    echarts 立体柱
    k8s生产环境启用防火墙,要开启的端口
    一篇文章为你图解Kubernetes网络通信原理
  • 原文地址:https://www.cnblogs.com/lph970417/p/12079432.html
Copyright © 2020-2023  润新知