Problems using rootpy over ssh

Hi everyone,
I am having some trouble using rootpy over SSH. It only happens intermittently so I am having real trouble working out what the problem is. My function starts off with:

def PtDifferential(InputCentral, InputHalf, InputDouble):

import ROOT
import numpy as np
import sys
import rootpy
from   rootpy.plotting import Hist, HistStack, Legend, Canvas
from import get_style, set_style
from   rootpy.interactive import wait
from   rootpy import asrootpy
import rootpy.plotting.root2matplotlib as rplt

and then goes on to manipulate some histograms eventually saving them to *.pdf files. But sometimes I get the following error:

DISPLAY not set, setting it to
WARNING:rootpy.interactive.rootwait] unable to access ROOT’s GUI thread either because PyROOT’s finalSetup() was called while in batch mode or because PyROOT is using the new PyOS_InputHook based mechanism that is not yet supported in rootpy (PyConfig.StartGuiThread == ‘inputhook’ or gSystem.InheritsFrom(‘TMacOSXSystem’)). wait() etc. will instead call raw_input() and wait for [Enter]
Traceback (most recent call last):
File “”, line 1217, in
PtDifferential(“LatestShowered”, “ShowwerHalf3”, “ShowwerDouble3”)
File “”, line 840, in PtDifferential
fig = plt.figure(figsize = (7, 5), dpi = 100, facecolor = ‘white’)
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/”, line 423, in figure
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/”, line 31, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/”, line 38, in new_figure_manager_given_figure
canvas = FigureCanvasQTAgg(figure)
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/”, line 70, in init
FigureCanvasQT.init( self, figure )
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/”, line 207, in init
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/”, line 62, in _create_qApp
raise RuntimeError(‘Invalid DISPLAY variable’)
RuntimeError: Invalid DISPLAY variable

Any help would be greatly appreciated. Thanks

It sounds like the ssh connection wasn’t set up to allow graphics. Did you do ssh -X or ssh -Y, or just plain ssh?

The easiest way to test if your ssh connection can forward graphics is by trying to run the program “xclock” which all unixes/linuxes should have. If you get the same error as using rootpy, then the error isn’t with rootpy, but with the connection.

There may be additional settings needed to allow graphics connections:


If you just want to save image files and don’t want matplotlib to attempt to create a graphical window you can do this:

import matplotlib matplotlib.use('Agg') # do this before importing pyplot from matplotlib import pyplot pyplot.ioff()

This puts matplotlib into a batch state similar to ROOT’s ROOT.gROOT.SetBatch(True).

By the way, a better place to ask questions regarding rootpy, although this one is more of a matplotlib question, is on the rootpy-users mailing list: (!forum/rootpy-users)

or on stackoverflow while tagging your question as rootpy (and matplotlib in this case):

If you find a rootpy bug, you can report it on rootpy’s issue tracker:

This way we get an email automatically with your question and you should get a quicker response.