Save plot from command line with no access to graphics

Viewed 56

I am attempting to save out a plot from a python script that is being run on a remote linux box with no access to GUI, and plt.plot() followed by plt.savrefig() esults in a graphics failure... is there a way to save out a plot from the command line without displaying it?

1 Answers

First I would atempt to save the graphic as an array to disk and then download it via SSL:

canvas.draw()       # draw the canvas, cache the renderer

image = np.fromstring(canvas.tostring_rgb(), dtype='uint8')

np.save('filename.npy', image)

alternatively you can try PIL, but I am not sure about your graphics issue:

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