# How to draw a bar chart?

**URL:** <https://root-forum.cern.ch/t/how-to-draw-a-bar-chart/57587>\
**Category:** Newbie\
**Created:** [December 18, 2023, 1:42pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-bar-chart/57587 "2023-12-18T13:42:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [December 18, 2023, 1:42pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-bar-chart/57587/1 "2023-12-18T13:42:07Z")

</div>

Hello everyone,

I have a long list of integers from the values 1, 2, 3, and 4.

I try plotting a histogram of the data using.

```auto
TH1* h_mult = new TH1I("h_mult", "Multiplicity", 5, 0, 5);

```

Then use the `bar`option to draw it, `h\_mult-\>Draw(“bar”)  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/d/a/da8766e25a6a4e0431ed5811bceb460c56ef0350.png)

`  
However, I cannot control the X-axis values such that the first bar is centered at x =1, the second bar at x =2, the third at x=3, and the fourth at x =4. Also, can only the labels x = 1,2,3 and 4 be displayed and not the intermediate values on the axis?

Can someone please help me in this regard? I think I know that what I am trying to get is a 'bar plot, ’ but I am unable to adjust the X-axis values.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [December 18, 2023, 1:50pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-bar-chart/57587/2 "2023-12-18T13:50:59Z")

</div>

> [@utkarsh-2000](#):
>
> However, I cannot control the X-axis values such that the first bar is centered at x =1, the second bar at x =2, the third at x=3, and the fourth at x =4.

Just change

```auto
TH1* h_mult = new TH1I("h_mult", "Multiplicity", 5, 0, 5);

```

to

```auto
TH1* h_mult = new TH1I("h_mult", "Multiplicity", 5, 0-0.5, 5-0.5);

```

> [@utkarsh-2000](#):
>
> Also, can only the labels x = 1,2,3 and 4 be displayed and not the intermediate values on the axis?

Sure, just add

```auto
h_mult->SetNdivisions(5);

```

after you have filled your histogram.

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [December 18, 2023, 1:59pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-bar-chart/57587/3 "2023-12-18T13:59:03Z")

</div>

> [@yus](#):
>
> `h_mult->SetNdivisions(5);`

Thanks a lot for the quick solution !

---

<div class="post-metadata">

**Author:** ![SapphireShade](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sapphireshade/32/35327_2.png) [@SapphireShade](https://root-forum.cern.ch/u/SapphireShade)\
**Post date:** [December 19, 2023, 9:19am UTC](https://root-forum.cern.ch/t/how-to-draw-a-bar-chart/57587/4 "2023-12-19T09:19:05Z")

</div>

I’ll try the method you suggested. I have slightly different data to process, but I hope the same principle will work for me.
