Re: Range of TGraph2D

From: Olivier Couet <couet_at_mail.cern.ch>
Date: Thu, 26 May 2005 09:42:08 +0200 (CEST)

Hello Akira,

This is now implemnted in the cvs head. Here is an example:

void graph2dhist()
{

   TCanvas *c = new TCanvas("c","Graph2D example",0,0,700,600);                                                                                 

   Double_t x, y, z, P = 6.;
   Int_t np = 300; // generate this many nodes                                                                                 

   TGraph2D *dt = new TGraph2D();
   TH2D* h2 = new TH2D("h2","h2",40,-6,6,40,-10,10);    dt->SetHistogram(h2);                                                                                 

   TRandom *r = new TRandom();                                                                                 

   for (Int_t N=0; N<np; N++) {

      x = 2*P*(r->Rndm(N))-P;
      y = 2*P*(r->Rndm(N))-P;
      z = (sin(x)/x)*(sin(y)/y)+0.2;
      dt->SetPoint(N,x,y,z);

   }
   gStyle->SetPalette(1);                                                                                 

   dt->Draw("TRI1 p0");
}

Olivier

On Wed, 25 May 2005, Olivier Couet wrote:

>
> Hello,
>
> I think the best would be to use a function like SetHistogram. It is
> available in TGraph but not in TGraph2D. I will implement it. I let you
> know when it is ready.
>
> O.Couet
>
> On Wed, 25 May 2005, OKUMURA, Akira wrote:
>
> > Hello ROOTers,
> >
> > (ROOT 4.00.08 on RH 7.3)
> >
> > I would like to change the range of axes of TGraph2D.
> > In other words, I would like to zoom out the TGraph2D. (NOT zoom in)
> > TGraph2D->GetXaxis()->SetRangeUser() is not suitable to this porpose,
> > because it automatically corrects overflows and underflows.
> >
> > Then I tried using a dummy TH2D frame and "same" option as follows.
> > 'dt' is drawn on the same pad, but axes ranges are NOT x[-250, 50]
> > y[-150,150].
> > (Only labels are correct.)
> >
> > How can I do ?
> >
> > void test()
> > {
> > TCanvas *C = new TCanvas;
> > TGraph2D *dt = new TGraph2D;
> >
> > Double_t x,y,z;
> > Int_t i, np = 0;
> >
> > ifstream fin;
> > fin.open("out.dat");
> > while (!fin.eof()) {
> > fin >> i >> x >> y >> z;
> > if (!fin.eof()) {
> > dt->SetPoint(np, x, y, z+15);
> > np++;
> > } // if
> > } // while
> > fin.close();
> >
> > TH2D* frame = new TH2D("frame", "", 1, -250, 50, 1, -150,150);
> > frame->SetMaximum(15.);
> > frame->SetMinimum(-5.);
> > frame->SetStats(kFALSE);
> > frame->Draw("surf");
> >
> > dt->SetMaximum(15.);
> > dt->SetMinimum(-5.);
> > dt->Draw("surf4 same");
> >
> > return;
> > }
> >
> > OKUMURA, Akira oxon_at_icrr.u-tokyo.ac.jp
> > Institute for Cosmic Ray Research, University of Tokyo
> > 5-1-5 Kashiwanoha Kashiwa Chiba 277-8582 Japan
> > Tel/Fax : +81 4-7136-3153
> > Skype : okumura.akira
> >
> >
>
>

-- 
Org:    CERN - European Laboratory for Particle Physics.
Mail:   1211 Geneve 23 - Switzerland                     Mailbox: J25910      
E-Mail: Olivier.Couet_at_cern.ch                            Phone:   +41 22 7676522
WWW:    http://cern.ch/Olivier.Couet/                    Fax:     +41 22 7670300
Received on Thu May 26 2005 - 09:42:14 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:08 MET