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?