Hi Peter,
I recently added a tutorial macro in $ROOTSYS/tutorials/two.C
to show a possible solution. Here is teh code.
Rene Brun
void two()
{
//example of macro illustrating how to superimpose two histograms
//with different scales in the "same" pad.
TCanvas *c1 = new TCanvas("c1","example of two overlapping
pads",600,400);
//create/fill draw h1
gStyle->SetOptStat(kFALSE);
TH1F *h1 = new TH1F("h1","my histogram",100,-3,3);
Int_t i;
for (i=0;i<10000;i++) h1->Fill(gRandom->Gaus(0,1));
h1->Draw();
c1->Update();
//create hint1 filled with the bins integral of h1
TH1F *hint1 = new TH1F("hint1","h1 bins integral",100,-3,3);
Float_t sum = 0;
for (i=1;i<=100;i++) {
sum += h1->GetBinContent(i);
hint1->SetBinContent(i,sum);
}
//scale hint1 to the pad coordinates
Float_t rightmax = 1.1*hint1->GetMaximum();
Float_t scale = gPad->GetUymax()/rightmax;
hint1->SetLineColor(kRed);
hint1->Scale(scale);
hint1->Draw("same");
//draw an axis on the right side
TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"+L");
axis->SetLineColor(kRed);
axis->SetTextColor(kRed);
axis->Draw();
}
On Fri, 14 Jan 2000, Peter Sanders wrote:
>
> Rooters,
>
> I am trying to overlay two histograms with the same x-axis but
> very different y-axes. I want to put the different y-axes on the
> left and right hand sides.
>
> I have two difficulties in achieving this:
>
> 1) gPad->SetTicky() does not exclusively put a scale on the RHS but is
> always in addition to the scale on the left.
>
> 2) gPad->SetFillType(4000) while making the pad transparent doesn't make
> the histogram within the pad transparent.
>
> Any insights or alternative ways ?
>
> Pete
>
> p.sanders@ic.ac.uk
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:17 MET