I'm running a python script on a remote server via SSH, however at the end I require it to save a graph using pyplot, which requires the X server to be active. As this runs for a long time I have been using the "screen" command and leaving it then resuming when I come back. The problem with this is that the resumed screen attempts to output to whatever X display SSH was using the first time I connected (e.g. localhost:15.0) however often by the time I return either the local machine or the server has assigned me a different one (e.g. localhost:22.0) and so the code breaks as it can't find anywhere to output.

Is there any way I can stop this timing out or set which display I wish to use from within the SSH session? I have tried connecting using -X and -Y and there is no change?


1 Answer 1


To start, you'd probably be better off just using some other plotting library like matplotlib which doesn't require an X framebuffer.

If you absolutely must use pyplot, try starting up Xvfb (a virtual X server) on the remote end and point the $DISPLAY variable at it instead of the forwarded X display. That way it will run inside the screen without problems.

  • I was under the impression matplotlib's plotting WAS pyplot?
    – Mithra
    Apr 17, 2012 at 16:41
  • Er, sorry, I meant to use another library call that doesn't require an X framebuffer, like savefig().
    – jsbillings
    Apr 17, 2012 at 16:44
  • Will try the Xvfb method. I'm only trying to save the figure rather than outputting it however even creating a subplot in pyplot seems to require X.
    – Mithra
    Apr 17, 2012 at 16:57
  • Fixed it! Thanks for the help, Xvfb didn't exist on the server I needed to use but changed the backend matplotlib uses to Agg and that did the trick. Cheers again for the advice.
    – Mithra
    Apr 17, 2012 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .