Re: [ROOT] Histograms on TCanvas without space between them

From: Olivier Couet (Olivier.Couet@cern.ch)
Date: Wed Apr 07 2004 - 16:00:48 MEST


Hi Kay,

 When you do "Divide()" on a Pad it divides it in sub-pads laying on a 
regular grid. Each TPad produced from that division contains a TFrame. The 
SetXXXMargin methods act on the distances between that TFrame and the TPad 
borders. So when you set the Left and right margins to zero for the middle 
TPad(s) the TFrame inside get twice more space than its colleagues laying 
in TPad(s) on borders. So TPads sizes should be adapted to handle that. 
Here is a very small macro showing a possible way to do it:

void stack() {

   TCanvas *c1 = new TCanvas("c1","multipads", 600, 500);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);

   Double_t W  = 0.3;          // Pad Width
   Int_t    Nx = 3;            // Number of pads along X
   Double_t Xm = (1-(Nx*W))/2; // X Margin
   Double_t dw = (W*0.1)/4;

   TPad *p1 = new TPad("p1", "p1", Xm, 0.2, Xm+W+dw, 0.8, 0, 0, 0);
   p1->SetRightMargin(0);
   p1->Draw();

   TPad *p2 = new TPad("p2", "p2", Xm+W+dw, 0.2, Xm+2*W-dw, 0.8, 0, 0, 0);
   p2->SetRightMargin(0);
   p2->SetLeftMargin(0);
   p2->Draw();

   TPad *p3 = new TPad("p3", "p3", Xm+2*W-dw, 0.2, Xm+3*W, 0.8, 0, 0, 0);  
   p3->SetLeftMargin(0);
   p3->Draw();

   TH1F *h1 = new TH1F("h1","test1",20,-3,3);
   TH1F *h2 = (TH1F*)h1->Clone("h2");
   TH1F *h3 = (TH1F*)h1->Clone("h3");

   h1->FillRandom("gaus",500); h1->SetMaximum(80);
   h2->FillRandom("gaus",300); h2->SetMaximum(80);
   h3->FillRandom("gaus",900); h3->SetMaximum(130);

   p1->cd(); h1->Draw();
   p2->cd(); h2->Draw();
   p3->cd(); h3->Draw();
}

Cheers,       Olivier



On Wed, 7 Apr 2004, Kay Ulbrich wrote:

> On Tuesday, April 6, 2004, 16:37 +0200, Olivier Couet wrote:
> 
> > 
> > Hi,
> > 
> >  Have you a little example illustrating your problem ?
> > 
> >  Cheers,       Olivier
> > 
> > On Tue, 6 Apr 2004, Kay Ulbrich wrote:
> > 
> > > Hello,
> > > [ ... a lot loquatious of talk by me ... ] 
> > > Thank you for hints,
> > > Kay
> > > 
> > > 
> > > 
> > 
> > -- 
> > Org:    CERN - European Laboratory for Particle Physics.
> > Mail:   1211 Geneve 23 - Switzerland                     Mailbox: J25910      
> > E-Mail: Olivier.Couet@cern.ch                            Phone:   +41 22 7676522
> > WWW:    http://cern.ch/Olivier.Couet/                    Fax:     +41 22 7677155
> > 
> 
> Hello Olivier,
> 
> thank you for your prompt answer. Sorry, that it took me some time to
> give an example, because I have encapsuled the
> margin-set-functionality in a separate class derived from TCanvas.
> 
> Anyway, the example (a modfied one from Rene Brun in the thread I
> mentioned first) does the same. So one sees, that the "middle"
> histograms are wider than the outer ones. The same would apply to
> the height, if I had more than 2 rows.
> 
> I actually want to have all histograms the same size. On the other
> hand, I do not want to set ALL margins to 0 (this would do it),
> because then I would have to add the axis labels manually i.e. by
> using xfig.
> 
> I could live with adding the axis titles by an external program, but
> here it would be nice as well to "embed" the canvas (c1 in the
> example) centrally in a slightly bigger one and position
> TPaveText-objects relative to the NDC of the bigger canvas.
> 
> I have seen PAW generated plots which looked as I would like, but I
> have abstained from PAW and started with ROOT right away ...
> 
> Greetings,
> Kay
> 
> 

-- 
Org:    CERN - European Laboratory for Particle Physics.
Mail:   1211 Geneve 23 - Switzerland                     Mailbox: J25910      
E-Mail: Olivier.Couet@cern.ch                            Phone:   +41 22 7676522
WWW:    http://cern.ch/Olivier.Couet/                    Fax:     +41 22 7677155



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:07 MET