简体   繁体   English

可以在没有DISPLAY的情况下使用pyplot吗?

[英]Possible to use pyplot without DISPLAY?

I'm working remotely on a machine that's pretty restrictive. 我正在一台相当严格的机器上远程工作。 I can't install any software, and it won't accept my X11 session, so I have no display. 我无法安装任何软件,也不接受我的X11会话,因此我没有显示。 The machine currently has pylab installed, and I'd like to use it to plot something and then save it for viewing on another computer. 机器目前安装了pylab,我想用它绘制一些东西,然后将其保存以便在另一台计算机上查看。 However, it seems there's no way to even create a plot without a display. 但是,似乎没有办法在没有显示器的情况下创建绘图。 Am I missing something? 我错过了什么吗?

Use another backend, for example Agg or SVG: 使用另一个后端,例如Agg或SVG:

import matplotlib
matplotlib.use('Agg')
...
matplotlib.savefig('out.png')

Yes, after creating the plots etc., instead of calling 是的,在创建情节等之后,而不是打电话

pylab.show()

call 呼叫

pylab.savefig('filename.XXX')

where XXX is one of the common image extensions (png, jpg...) 其中XXX是常见的图片扩展名之一(png,jpg ...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM