# How to draw histograms in colz text e

**URL:** <https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037>\
**Category:** ROOT\
**Created:** [August 28, 2017, 4:39am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037 "2017-08-28T04:39:00Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![addi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@addi](https://root-forum.cern.ch/u/addi)\
**Post date:** [August 28, 2017, 4:39am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/1 "2017-08-28T04:39:00Z")

</div>

Hi all,

I am new in root, sorry in advance if my questions seems basic to you. I want to get a 1D histogram from a .root file and draw it in a colz text e. But the problem is i donot know how to make these boxes of any rang. Like in x-axis i want a box range of {0,10,30,60,100,200} where in y-axis {0,1,1.6,2,2.4,3}.  
Kindly help me to do it as soon as possible. I am attaching a sample plot taken from internet.

Thank you.  
Adi

![sample](https://root-forum.cern.ch/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 28, 2017, 5:32am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/2 "2017-08-28T05:32:53Z")

</div>

Hi Adi,

what is a “box range of {0,10,30,60,100,200} where in y-axis {0,1,1.6,2,2.4,3}” ? In 2D, to draw a rectangle, I would expect 4 x,y coordinates.

cheers,  
D

---

<div class="post-metadata">

**Author:** ![addi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@addi](https://root-forum.cern.ch/u/addi)\
**Post date:** [August 28, 2017, 5:37am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/3 "2017-08-28T05:37:09Z")

</div>

Hi dpiparo,

I want to plot a 2D histogram in colz text e. Where these values are x axis limits and y axis limits. Sample plot is attached below

 ![sample](https://root-forum.cern.ch/uploads/default/original/2X/e/ec00136335d1f5d41af0ff10d2f0484395aa871b.PNG)

---

<div class="post-metadata">

**Author:** ![addi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@addi](https://root-forum.cern.ch/u/addi)\
**Post date:** [August 28, 2017, 5:38am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/4 "2017-08-28T05:38:17Z")

</div>

The boxes means 20-40 in x axis and 0-1 in y axis.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 28, 2017, 5:38am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/5 "2017-08-28T05:38:25Z")

</div>

Hi,

there is a constructor to achieve that: [https://root.cern.ch/doc/master/classTH2F.html#a94c487e4997c33b59b9ea69a8e74ad26](https://root.cern.ch/doc/master/classTH2F.html#a94c487e4997c33b59b9ea69a8e74ad26)

cheers,  
D

---

<div class="post-metadata">

**Author:** ![addi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@addi](https://root-forum.cern.ch/u/addi)\
**Post date:** [August 28, 2017, 5:42am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/6 "2017-08-28T05:42:41Z")

</div>

Hi D,

Constructor only changes the x-axis in one bin i mean let 0-20. similarly in y. I want to change x in 5 different bin sizes.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 28, 2017, 5:43am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/7 "2017-08-28T05:43:35Z")

</div>

Hi,

I do not understand the statement. You can pass the bin edges you need to the constructor, can’t you?

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![addi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@addi](https://root-forum.cern.ch/u/addi)\
**Post date:** [August 28, 2017, 5:49am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/8 "2017-08-28T05:49:35Z")

</div>

Hi D,

I am sending you these few lines. Hope so it will make easy for you understand it.

```auto
   TFile *f1 = new TFile("merge.root");
TH2F *h2 = (TH2F*)gDirectory->Get("pt_eta");
   double bins_x[] = {10, 20, 40, 70, 100,200};
  double bins_y[] = {0, 1, 1.5, 2.5,3};
TH2F *h2 = new TH2F("h2", "pteta",(sizeof(bins_x) / sizeof(double) - 1), bins_x, (sizeof(bins_y) / sizeof(double) - 1), bins_y);
h2->Draw(colz text e);

```

What i am doing is this. It will draw the the plot like posted above. But it is not drawing like the above mensioned plot. How would I achieve this.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 28, 2017, 7:03am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/9 "2017-08-28T07:03:22Z")

</div>

Hi,

I am not sure I get it. h2 seems to be empty.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![addi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@addi](https://root-forum.cern.ch/u/addi)\
**Post date:** [August 28, 2017, 7:10am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/10 "2017-08-28T07:10:03Z")

</div>

Then how would I can do it? Can someone else help me to do it. I need to it urgently.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 28, 2017, 7:20am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/11 "2017-08-28T07:20:47Z")

</div>

Hi,

you created an empty histogram, you need to fill it with the content you would like to display.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![addi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@addi](https://root-forum.cern.ch/u/addi)\
**Post date:** [August 28, 2017, 7:22am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/12 "2017-08-28T07:22:50Z")

</div>

Hi D,

Of course i will fill the histogram with some data. All I want to know is how I can write the command to make such a histogram.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 28, 2017, 7:27am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/13 "2017-08-28T07:27:46Z")

</div>

Hi,

the command you have is correct. The issue is that presently your histogram is empty.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 28, 2017, 9:12am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/14 "2017-08-28T09:12:22Z")

</div>

[You need to use the “correct” binning when you create and fill your “pt\_eta” histogram, the one that is stored in your “merge.root” file (and check if it is a TH2F or a TH2D).](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/4)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 30, 2017, 11:53am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/15 "2017-08-30T11:53:53Z")

</div>

> [@Problem in 2D histograms calculations](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/11):
>
> Until a proper “rebin” method for 2-D histograms is implemented (if ever), you can try to use the attached macro. [nt2.cc](https://root-forum.cern.ch/uploads/default/original/2X/e/e4dadb39641dc7aade37004e90fc77c33a5a7206.cc) (5.6 KB)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [September 13, 2017, 11:54am UTC](https://root-forum.cern.ch/t/how-to-draw-histograms-in-colz-text-e/26037/16 "2017-09-13T11:54:05Z")

</div>

Closed on September 13, 2017, 11:54am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
