# 2D Histogram - similar to imshow() in python

**URL:** <https://root-forum.cern.ch/t/2d-histogram-similar-to-imshow-in-python/51109>\
**Category:** Newbie\
**Created:** [August 8, 2022, 3:11pm UTC](https://root-forum.cern.ch/t/2d-histogram-similar-to-imshow-in-python/51109 "2022-08-08T15:11:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheScientist](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@TheScientist](https://root-forum.cern.ch/u/TheScientist)\
**Post date:** [August 8, 2022, 3:11pm UTC](https://root-forum.cern.ch/t/2d-histogram-similar-to-imshow-in-python/51109/1 "2022-08-08T15:11:12Z")

</div>

I am trying to create a 2D histogram similar to the one shown below in ROOT/PyROOT.

In python, it was made with imshow() as the data structure is in 2D array:  
wire1/channel number1 [( ADC1, ADC2, …)]  
wire2/channelnumber2 [(ADC1, ADC2 )]

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/d/6/d6ea2615ebe4bbc5407192f4d641af1d759bf16b.jpeg)

I have a root file with branch as channel number with ADC value inside it.  
I was able to create a 2D histogram up to this point for only one channel:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/8/4/84b3e1302292a0df6c83e12377f9dca4d294f822.png)

I am not sure how to get all the channels in x-axis as shown in the first plot and ADC values in the “count section”. Please help me out. Thank you.

My code:

```auto
 4 void code8()
  5 {
  6 TFile *fInput = new TFile("js2rt.root", "READ"); //READ
  7 TTree *tree = (TTree*)fInput->Get("0");
  8 
  9 Int_t chn0;
 10 tree->SetBranchAddress("chn0", &chn0);
 11 //tree->SetBranchAddress("z", &z);
 12 
 13 TH2D* hist = new TH2D("Chn_adc_hist", "Time ticks vs ADC; ADC; Time ticks", 1000, 1100, 1200 ,1000, 0, 750 );
 14 
 15 Int_t entries = tree->GetEntries("chn0");
 16 
 17 for(Int_t i = 0; i < entries; i++) {
 18 
 19 Int_t ticks = i; //timeticks
 20 tree->GetEntry(i);
 21 hist->Fill(chn0, ticks);
 22 
 23 }
 24 
 25 hist->Draw("COLZ2");
 26 }
~           

```

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [August 16, 2022, 8:51am UTC](https://root-forum.cern.ch/t/2d-histogram-similar-to-imshow-in-python/51109/2 "2022-08-16T08:51:46Z")

</div>

Is your wire number stored somewhere in your tree? Or is it cyclical from 1 to 128 or something like that?

you will need to call `hist->Fill(wireNumber, ticks, z)`

where the third argument is the weight (color) you want to show/add.
