# Plots in Histogram

**URL:** <https://root-forum.cern.ch/t/plots-in-histogram/63142>\
**Category:** ROOT\
**Tags:** hist\
**Created:** [March 16, 2025, 4:13pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142 "2025-03-16T16:13:56Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 16, 2025, 4:13pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/1 "2025-03-16T16:13:57Z")

</div>

Greetings!  
I’m Zeeshan, theoretical particle physics research student.  
We are working on histograms like draw some plots, but there are some issues regarding smoothness and position of legends in Canva. So please guide us if someone has knowledge/experience regarding that.  
Our target is to draw smooth three plots but one of them is almost done but remaining two still unsolved so kindly let us fix it?  
Here are commands to run it in root.  
Open root as following…!  
zeeshan@zeeshan:~/root$ root -l  
root [0] .L normal\_spectr02.cpp  
root [1] main()  
[normal\_spectr02.cpp](https://root-forum.cern.ch/uploads/short-url/mHexGNM0RDdPQnJLGYYLhonUQkP.cpp) (44.7 KB)  
I have attached file and reference with which, we have to match our results

 ![01](https://root-forum.cern.ch/uploads/default/original/3X/4/8/48e4f2f15bab74a4cf1ebcbb0340f4b933d68374.jpeg)  
In last, that’s our outcomes after running above commands/code but that’s not according to the reference plots.  
 ![twopads_ratio_Cen0_3](https://root-forum.cern.ch/uploads/default/original/3X/9/4/94d2bad033ebf72fed1e0eaa1af2802c7aabb313.jpeg)  
Kindly help us to fix it…?

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 17, 2025, 5:18am UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/2 "2025-03-17T05:18:02Z")

</div>

I’d say you have to be much clearer in describing your issue, what you expect and what is “wrong” with what you are getting (or whether you are not getting anything, but in this case it seems your code runs well but the problem is only the aesthetics?). So please describe what you get and what exactly you want to change. In all cases, showing a 1200+ lines macro is far from ideal too, hardly anyone will go through that, especially when what you want is not clear. Try first to (greatly) reduce the code to a minimum that (ideally) we can also run to reproduce your problem.  
The above being said, by looking at the very last lines in your macro it seems that your graph is the one at the bottom of your post (and you want it to look similar to the 3 that are together above?). For the y-axis title, for instance, if you don’t want it in 2 lines, don’t use `#frac`, just type the formula as you would in a line of text (e.g. `1/(2#pi)` etc.). For the TLegend position you’ll have to play around until you find a position you like --if you run the macro in interactive move, as you are doing, you can move the TLegend with the mouse to a position and size you like, then save the canvas as a .C file (menu File → Save As… and give it some name.C) and then open that .C file and see the coordinates of the TLegend, to use those in your code.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 24, 2025, 12:57pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/3 "2025-03-24T12:57:02Z")

</div>

Respected… I have attached code file and that’s results which, we should to align as sample image (also attached)

 ![Sample](https://root-forum.cern.ch/uploads/default/original/3X/4/3/4333a0d89dad388dcf684ecfa56a67683bfabfff.jpeg)  
 ![AllPlus_Cen4](https://root-forum.cern.ch/uploads/default/original/3X/1/7/1769213b848723e3313f145a20a9ef0e128c2538.jpeg)  
[AllPlus\_Cen0.C](https://root-forum.cern.ch/uploads/short-url/lwmQ6l0Z3FaFZDINzqI6KH42Sux.C) (53.8 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 24, 2025, 1:02pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/4 "2025-03-24T13:02:55Z")

</div>

Your macro gives me the following plot. What’s wrong with it ?

 ![Screenshot 2025-03-24 at 14.02.36](https://root-forum.cern.ch/uploads/default/original/3X/c/8/c86dbb28b5cdb84249300b6ed486866377d487ac.jpeg)

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 24, 2025, 1:08pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/5 "2025-03-24T13:08:42Z")

</div>

Honorable Sir, we are also stuck. When maximize it, then it shows as above.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 24, 2025, 1:13pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/6 "2025-03-24T13:13:29Z")

</div>

[AllPlus\_Cen4.C](https://root-forum.cern.ch/uploads/short-url/avq3oXI2c7uWoWk75HceWRmibJI.C) (5.1 KB)  
I’m sorry sir. Please check it. This is 30-40%

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 24, 2025, 1:16pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/7 "2025-03-24T13:16:43Z")

</div>

Dear @Muhammad_Zeeshan,  
I am not saying I am stuck. I just say that your macro gives the previously attached plot and I would like to know what do you think is wrong in that plot. Can you explain it so we can help you to fix your problem ? I simply ran your macro without any modification except the first line which I changed to `void AllPlus_Cen0()`:  
[AllPlus\_Cen0.C](https://root-forum.cern.ch/uploads/short-url/zeuVd4TQ8fq6H7fORLsJhw4z0jI.C) (53.8 KB)

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 24, 2025, 1:21pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/8 "2025-03-24T13:21:52Z")

</div>

Actually Sir, with due respect, I meant me and my research fellow, we both are stuck in this problem. So let me correct my previous words that we are hanged. Our task is to make smooth plots as given sample.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 24, 2025, 1:28pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/9 "2025-03-24T13:28:06Z")

</div>

I am afraid we cannot help you a lot with the macro you sent. This macro was produce with `SaveAs(...)`. The plot produced is reflecting the static data setting in this macro. Your question looks more general and we cannot help you with the macro. You sent. To summarize it the code in your macro produces something correct.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 24, 2025, 1:57pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/10 "2025-03-24T13:57:54Z")

</div>

Sure sir. I can understand, but just let me guide to set position of legends on canvas?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 24, 2025, 2:03pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/11 "2025-03-24T14:03:48Z")

</div>

The [TLegend](https://root.cern/doc/v632/classTLegend.html#a1f4a3d8b87bcbaea924470e8df416aaa) is defined by this line:

```auto
   TLegend *leg = new TLegend(0.2431078, 0.173913, 0.5250627, 0.373913,NULL,"brNDC");

```

The for numbers are the position of the legend in normalized space. (x1, y1, x2, y2). Change these numbers to move the legend.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 24, 2025, 2:06pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/12 "2025-03-24T14:06:52Z")

</div>

Thank you, respected sir. Just one thing more, how can we smooth plots on canvas?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 24, 2025, 2:15pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/13 "2025-03-24T14:15:09Z")

</div>

> [@Muhammad\_Zeeshan](#):
>
> how can we smooth plots on canvas?

Your data are stored into TH1D. You can use [TH1::Smooth](https://root.cern/doc/v632/classTH1.html#a0d08651c37b622f4bcc0e1a0affefb33)

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [March 28, 2025, 5:50pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/14 "2025-03-28T17:50:08Z")

</div>

Greetings. Let me guide to run this code in root via Ubuntu terminal  
[normal\_spectr02.cpp](https://root-forum.cern.ch/uploads/short-url/y6vo7r0VmdjRRObe26WVAh9ibAu.cpp) (45.0 KB)  
root -l normal\_spectr02.cpp  
main()  
Then an error is showing… Like

 ![Screenshot from 2025-03-28 22-44-09](https://root-forum.cern.ch/uploads/default/original/3X/4/4/44455cae020c54975da04122332b883ddb0bcb76.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 31, 2025, 7:56am UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/15 "2025-03-31T07:56:00Z")

</div>

`hist_Norm`, used the first time at line 42 of your script, is not declared.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [April 2, 2025, 6:49pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/16 "2025-04-02T18:49:40Z")

</div>

Respected @couet. Greetings.  
I am stuck in to fix the following error when running a code via root.  
So, please need your guidance.  
[normal\_spectr02.cpp](https://root-forum.cern.ch/uploads/short-url/62XFbjIEG0DLoUcIhuTGf2591v5.cpp) (43.6 KB)  
Commands are:  
root-l normal\_spectr02.cpp  
main()

 ![Screenshot from 2025-04-02 23-48-06](https://root-forum.cern.ch/uploads/default/original/3X/1/0/10a976328d046e593313063dbdbf108ff8fad37e.png)

---

<div class="post-metadata">

**Author:** ![Muhammad\_Zeeshan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_zeeshan/32/38045_2.png) [@Muhammad\_Zeeshan](https://root-forum.cern.ch/u/Muhammad_Zeeshan)\
**Post date:** [April 2, 2025, 7:11pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/17 "2025-04-02T19:11:35Z")

</div>

I get the solution. Thanks Sir. Actually, in root file there is name simple Lambda instead of Lambda Plus.

---

<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:** [April 16, 2025, 7:11pm UTC](https://root-forum.cern.ch/t/plots-in-histogram/63142/18 "2025-04-16T19:11:49Z")

</div>

Closed on April 16, 2025, 7:11pm UTC

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