Re: [ROOT] - Drawing to scale

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Jan 23 2003 - 14:52:08 MET


Hi Caius,

See the script example below
You can also use the context menu item TPad::setFixAspectRatio

Rene Brun

{
   gROOT->Reset();
   
   //method1. compute ymax to get a commensurate range
   // 1 pixel must correspond to the same range in x and y
   TCanvas c1("c1","c1",10,10,800,600);
   Float_t xmin = 0;
   Float_t xmax = 20;
   Float_t ymin = -2;
   Int_t npx = gPad->GetWw();
   Int_t npy = gPad->GetWh();
   Float_t ymax = ymin + (xmax-xmin)*npy/npx;
   TH2F h("h","",20,xmin,xmax,20,ymin,ymax);
   h.Draw();
   TArc a1(6,4,6);
   a1.Draw();
   
   //method2. set a square virtual canvas size in a non-square canvas 
   TCanvas c2("c2","c2",200,50,800,600);
   c2.SetCanvasSize(700,700);
   c2.DrawFrame(0,0,20,20);
   TArc a2(10,10,10);
   a2.Draw();
}



Caius Howcroft wrote:
> 
> Hi,
> 
> This is something that has bothered me quite a few times.  I assume there
> must be an easy way of doing it, as it seems to be the kind of thing that
> one might want to do quite often.
> 
> I want to draw a a histogram/collection of points (hits in a detector). I
> want to lock the relative scale of the x/y (and maybe z) axis so the event
> always appears in the correct proportions.  Is there any neat way of doing
> this?
> 
> It would also be neat to be able to zoom keeping the event correctly
> scaled.
> 
> Sorry, probably a dumb question.
> 
> Cheers
>            Caius
> 
> ________________________________________
> -           CAIUS HOWCROFT             -
> -  +44 (0)1223 764 128      UK(office) -
> ========================================



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:08 MET