TAxis::DrawOption not coded?

hi there,
I am trying to have two histograms sharing the y-axis… Seemingly it is almost simple :

[code]import ROOT

c=ROOT.TCanvas()
c.Divide(2,1,0.,0.)
c.cd(1)
h1=ROOT.TH1F(“h1”,"",100,0,1)
h1.SetStats(0)
h2=ROOT.TH1F(“h2”,"",100,0,1)
h2.SetStats(0)
h2.GetYaxis().SetDrawOption(“±”)

c.cd(1)
h1.Draw()
c.cd(2)
h2.Draw()
c.Update()
[/code]
The catch is that the SetDrawOption does not seem to be implemented, as can be verified in http://root.cern.ch/root/htmldoc/src/TAxis.h.html : virtual void SetDrawOption(Option_t * /*option*/ ="") { }
Why is that so? Does that mean that I have to create a TGaxis instance for the y-axis, just in order to have ticks on both sides?

thanks,
Johann

This is done on purpose. SetDrawOption makes sense only for the object for which you have called object.Draw. TAxis is in general an embedded object in classes like TH1.

Rene

hi Rene,
ok, fine. In the meantime I tried something else :

import ROOT

c=ROOT.TCanvas()
c.SetBorderMode(0)
c.Range(-1,1,-1,1)
c.Divide(2,1,0.0,0.0)
c.cd(1)
h1=ROOT.TH1F("h1","",100,0,1)
h1.SetStats(0)
h2=ROOT.TH1F("h2","",100,0,1)
h2.SetStats(0)
#h2.GetYaxis().SetDrawOption("+-")
centralx=h1.GetXaxis().GetXmax()
ymin=h1.GetYaxis().GetXmin()
ymax=h1.GetYaxis().GetXmax()
ndiv=h1.GetYaxis().GetNdivisions()

c.cd(1)
h1.Draw()
c.cd(2)
h2.Draw()
c.Update()
c.cd(1)
centraly = ROOT.TGaxis(centralx,ymin,centralx,ymax,ymin,ymax,ndiv,"+-U")
centraly.Draw()
centraly.SetNdivisions(508)
c.Update()

Now this looks like what I would like to have (apart from the central tick label that I need to take care of…)
But I have a fefw questions :

  1. Why can’t I just pick up the Ndivisions value from the h1 y-axis and use it for the central axis?
  2. The right ticks of the central axis are actually hidden by the right panel. One can modify pass the argument “A” to h2.Draw() to check that. Is it possible to send the right pad “to the back” so that the central axis sits above it and is visible?
  3. Why do the 2 pads behave differently when I try to move them with the mouse?
  4. Last but not least, how would a ROOT expert go about making such axis-sharing figures? It goes without saying that I have graphs that I want to add to each pad eventually.

thanks a lot for your help!
Johann

Johann,

If your intention is simply to add tick marks to the Y axis on the right side of the pad, you can simplify your script as shown below (in C++)

{ TCanvas c; c.SetBorderMode(0); c.Divide(2,1,0.0,0.0); c.cd(1); gPad->SetTicky(); h1= new TH1F("h1","",100,0,1); h1->SetStats(0); h2= new TH1F("h2","",100,0,1); h2->SetStats(0); h1->Draw(); c.cd(2); h2->Draw(); }

Rene