Re: [ROOT] 2 Histograms sharing a same x-axis

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Jun 30 2000 - 15:13:44 MEST


Hi Laurent,
You may get some inspiration from the two macros in attachment

Rene Brun

Laurent APHECETCHE wrote:
> 
> Hi Rooters,
> 
> I would like to plot 2 histograms which share the same x-axis :
> 
> ---------------
> |             |
> |             |
> |             |
> --|--|--|--|---
> |             |
> |             |
> |             |
> ---------------
> 
> I've tried to use TCanvas::Divide and play with the margins, but I
> failed.
> Any help ?
> 
> Thanks.
> --
> Dr. Laurent APHECETCHE (mailto:aphecetc@in2p3.fr) | TAPS/PHENIX/ALICE
> SUBATECH-Ecole des Mines de Nantes-4 rue Alfred Kastler-44070 NANTES
> cedex 03
> TEL (+33/0) 2 51 85 84 17 - FAX (+33/0) 2 51 85 84 24 (France)
> http://www-subatech.in2p3.fr/~photons -
> http://www.phenix.bnl.gov/~aphecetc

{
   gROOT->Reset();
   TCanvas c1("c1","multipads",700,700);
   gStyle->SetPadBorderMode(0);
   gStyle->SetFrameBorderMode(0);
   Float_t small = 1e-5;
   c1.Divide(1,2,small,small);
   TH1F h1("h1","test1",40,-4,4);
   TH1F h2("h2","test2",40,-4,4);
   h1.FillRandom("gaus",1000);
   h2.FillRandom("gaus",1000);
   
   c1.cd(1);
   gPad->SetBottomMargin(small);
   h1.Draw();

   
   c1.cd(2);
   gPad->SetTopMargin(small);
   gPad->SetTickx();
   h2.Draw();
}      


{
   gROOT->Reset();
   TCanvas c1("c1","multipads",700,700);
   gStyle->SetPadBorderMode(0);
   gStyle->SetFrameBorderMode(0);
   Float_t small = 1e-5;
   c1.Divide(2,2,small,small);
   TH1F h1("h1","test1",40,-4,4);
   TH1F h2("h2","test2",40,-4,4);
   TH1F h3("h3","test3",40,-4,4);
   TH1F h4("h4","test4",40,-4,4);
   h1.FillRandom("gaus",1000);
   h2.FillRandom("gaus",1000);
   h3.FillRandom("gaus",1000);
   h4.FillRandom("gaus",1000);
   
   c1.cd(1);
   gPad->SetBottomMargin(small);
   gPad->SetRightMargin(small);
   h1.Draw();

   c1.cd(2);
   gPad->SetBottomMargin(small);
   gPad->SetRightMargin(small);
   gPad->SetLeftMargin(small);
   h2.Draw();
   
   c1.cd(3);
   gPad->SetTopMargin(small);
   gPad->SetRightMargin(small);
   gPad->SetTickx();
   h3.Draw();

   c1.cd(4);
   gPad->SetTopMargin(small);
   gPad->SetRightMargin(small);
   gPad->SetLeftMargin(small);
   gPad->SetTickx();
   h4.Draw();
}      



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:29 MET