关于matplotlib的DISPLAY错误

  最近服务器系统重装了一下,原来跑得好好的程序出现了一个“TclError: no display name and no $DISPLAY environment variable”错误,百思不得其解,搜了很久,终于找到了解决办法,记录如下:

 

DISPLAY error matplotlib

When error occur about this "$DISPLAY not set" when you run Python code that use matplotlib this happened because your matplotlib backend is set to FltkAgg, GTK, GTKAgg, GTKCairo, TkAgg , Wx or WxAgg they required a GUI that why error occur.

To solve this you must specific other backend that not required GUI (Agg, Cairo, PS, PDF or SVG ) when use matplotlib like this

  • In code
    import matplotlib
    matplotlib.use('Agg')
  • In command line use -d option
    Python subplot_demo.py -dAgg

    Remember when call savefig('filename') don't give it extension this will handle by backend that you specific e.g Agg will create file filename.png

    source from --> http://matplotlib .sourceforge.net/backends.html

 

 

  资料来源:http://chewpichai.blogspot.com/2008/01/display-error-matplotlib.html 。原文可能被墙了,需要设法翻一下。

 

 

  

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值