Canvas.cd() problem

Hi there,
I have a PyROOT script and within it there seems to be a problem with changing canvas.
I’ve written a plain-English version of the script below… if there is no obvious/trivial problem with what I’m doing I could supply the exact code.

#instantiate 2 canvases
def plottingFunc(…pass in the 2 canvases, pass in a histogram…)

cd to canvas 1

draw a histogram on it

cd to canvas 2

make a ProfileX plot of the histogram above

plot this TProfile on canvas 2

print “Script has run to here”

#call the function above
plottingFunc(canv1,canv2,histo)

What happens when I run this script (in interactive mode) is this (the problem is at step 3):

  1. Canvas 1 is drawn and the histogram is put on it
  2. The script runs to the end (“Script has run to here” is printed)
  3. Canvas 2 REMAINS BLANK
  4. If I then interactively issue the command canvas2.cd(), the TProfile is then plotted on it. NB canvas2 is still in scope at this point

So, I can get my histogram and profile plot onto the 2 canvases, but I would prefer not to have to manually change to the 2nd canvas. Also, I would ideally like to plot something on a 3rd canvas, but this method of manually changing to the canvas does not seem to work when there are 3 of them.

Many thanks in advance for any help!
Sarah

doing a canvas2.Update() after finishing plotting on it could solve your problem

Hi MadCow,
thanks for your suggestion. The problem doesn’t seem to arise now that I’m back on a fast (CERN) internet connection. On home broadband the canvas.cd() command seems to get skipped over (even when I include a canvas.Update() in my script after the .cd() )
Best,
Sarah

Sarah,

on a normal, interactive prompt, all canvases are updated every time a new python line is reached (the call is in the python displayhook). However, that still runs on a separate thread, so may indeed take longer to actually display than the return of the prompt.

Cheers,
Wim