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

From: Manoj Jha (Manoj.Jha@cern.ch)
Date: Thu Mar 18 2004 - 16:27:42 MET

```Hi Rene,

Thanks for reply. I am trying to describe my problem in detail.
Suppose I had two one dimensional histogram. Let us say:

1. Pt distribution of electron
2. Eta ditribution of electron

Now, I want to plot Eta Vs. Pt of the electron. This is an example of
two dimensional histogram.  I followed the following steps

---------------------------------------------------------------------------------------------------------
TH2F *ETA_PT = new ("ETA_PT",  " Eta Vs. Pt of the electron", 1000,
-2.6,2.6,100,0,40);

for (i=0; i<nentries; i++)
ETA_PT -> Fill(ETA, PT);
------------------------------------------------------------------------------------------------------------

When I plot the ETA_PT, the output is scatter plot. That is entries are
plotted in the form of scattered point. But, I need the ETA_PT plot in
the form of histogram. That is, the entries should fill in histogram.

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);
>   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);
>   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");