在不访问图形的情况下从命令行保存绘图



我正试图从一个python脚本中保存一个绘图,该脚本正在一个无法访问GUI的远程linux盒子上运行,plt.plot((后面跟着plt.savreig((导致图形失败。。。有没有一种方法可以在不显示的情况下从命令行保存绘图?

首先我会声明将图形作为数组保存到磁盘,然后通过SSL:下载

canvas.draw()       # draw the canvas, cache the renderer
image = np.fromstring(canvas.tostring_rgb(), dtype='uint8')
np.save('filename.npy', image)

或者你可以试试PIL,但我不确定你的图形问题:

from PIL import Image
Image.fromarray(image).save("filename.png")