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

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


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