Re: [ROOT] How to plot two dimensional histogram ?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Mar 18 2004 - 22:44:05 MET


Hi,

I am still not sure to understand your request.
By default, a 2-D histogram is drawn as a scatter plot.
You can choose different draw options, eg
 h->Draw("lego").
See list of options at:

http://root.cern.ch/root/htmldoc/THistPainter.html#THistPainter:Paint

Rene Brun

On 
Thu, 18 Mar 
2004, Manoj 
Jha wrote:

> Hi Rene,
>     Thanks for reply. I am trying to describe my problem in detail. 
> Suppose I have two one dimensional histogram, i.e.,
> 
> 1. One dimensionalm Pt distribution of electron
> 2.  One dimensional Eta distribution of electron.
> 
> Now, I want to plot Eta vs. Pt of the electron. For this purpose, I have 
> to create a new two dimensional histogram as
> --------------------------------------------------------------------------------------------------------------------
> TH2F  *Eta_Pt  = new ("Eta_Pt" , " Eta  Vs. Pt of the electron", 
> 100,-2.6,2.6,100,0,40);
> 
> for (Int_t i=0; i<nentries; i++ )
>      Eta_Pt ->Fill(Eta, Pt);
> --------------------------------------------------------------------------------------------------------------------
> 
> The output of the above script is in the form of scatter plot. That is 
> the entries has been plotted as scattered point. Since by default, 2D 
> histograms are drawn as scatter plots. Thats why I am getting scatter 
> plot.  But I need the plot (Eta_Pt) in the form of  histogram. Please 
> let me know if you need any more informations.
> 
> Thanks and with regards,
> manoj
> 
> 
> 
> 
> 
> Rene Brun wrote:
> 
> >Hi,
> >
> >I am not sure to understand correctly your request.
> >The example in the attachement will may be give you some hints.
> >
> >Rene Brun
> >
> >Manoj Jha wrote:
> >  
> >
> >>Dear Rooters,
> >>   I have two one dimensional histograms. I want to plot theses two one
> >>dimenasional histograms as one two dimensional histogram.  For this
> >>purpose, I used TH2F to create the two dimensional histogram. When using
> >>TH2F, I am getting scatter plot. But, I need the two dimensional plot in
> >>the form of hitogram instead of scatter plot. Please let me know if you
> >>have solution for it.
> >>
> >>With best wishes,
> >>manoj jha
> >>    
> >>
> >>
> >
> >------------------------------------------------------------------------
> >
> >void manoj() {
> >   TCanvas *c1 = new TCanvas("c1","c1",600,900);
> >   c1->Divide(1,2);
> >   //method 1
> >   c1->cd(1);
> >   gPad->SetFrameFillColor(41);
> >   gPad->SetTheta(1.97);
> >   gPad->SetPhi(2.60);
> >   TH2F *h = new TH2F("h","test",30,-3,3,2,0,2);
> >   h->SetFillColor(38);
> >   h->GetYaxis()->SetNdivisions(2);
> >   TRandom r;
> >   for (int i=0;i<1000;i++) {
> >      h->Fill(1.3*r.Gaus(1,0.8),0.5);
> >      h->Fill(1.0*r.Gaus(-1,1),1.5,1.2);
> >   } 
> >   h->Draw("lego1");
> >   
> >   //method2
> >   c1->cd(2);
> >   gPad->SetFrameFillColor(41);
> >   gPad->SetTheta(1.97);
> >   gPad->SetPhi(2.60);
> >   TH2F *h1 = new TH2F("h1","test",30,-3,3,2,0,2);
> >   TH2F *h2 = new TH2F("h2","test",30,-3,3,2,0,2);
> >   h1->SetFillColor(38);
> >   h2->SetFillColor(50);
> >   for (int i=0;i<1000;i++) {
> >      h1->Fill(1.3*r.Gaus(1,0.8),0.5);
> >      h2->Fill(1.0*r.Gaus(-1,1),1.5,1.2);
> >   } 
> >   THStack *s = new THStack("s","test");
> >   s->Add(h1,"lego1");
> >   s->Add(h2,"lego1");
> >   s->Draw();  
> >   s->GetYaxis()->SetNdivisions(2);
> >}
> >  
> >
> 
> 



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