# Construct the histogram with unix time on X-axis

**URL:** <https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780>\
**Category:** Newbie\
**Created:** [April 28, 2022, 5:23am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780 "2022-04-28T05:23:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 28, 2022, 5:23am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/1 "2022-04-28T05:23:12Z")

</div>

I have a same data set with the unix time and its corresponding data  
EX.  
Unix time stamp Data  
1638338401- 43  
1638338432- 23  
1638338461- 24

I want to produce the 2D histogram with UNIX time on X-axis and Data set on Y-axis.

Thank You so much.

---

<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:** [April 28, 2022, 6:41am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/2 "2022-04-28T06:41:41Z")

</div>

[https://root.cern/doc/master/timeonaxis2\_8C.html](https://root.cern/doc/master/timeonaxis2_8C.html)

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 28, 2022, 4:49pm UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/3 "2022-04-28T16:49:30Z")

</div>

I am trying to add unix time on X-axis instead of date,  
also I didn’t understand the use of  
‘’'noise=f.Gaus(0.5\*(X1+X2), 0.1\*(X2-X1))

```
for(Int_t f = 0; f < nEntries; f++) //loop over to fill the histogram
{
    currentAna->GetEntry(f);
    //Double_t noise = f.Gaus(0.5*(X1+X2), 0.1*(X2-X1))
    curr_vals->Fill(abs(Curr));
}

```

‘’'void Histogram()

```
TDatime T0(2021, 12, 1, 0, 0, 0);
int X0 = T0.Convert();
gStyle->SetTimeOffset(X0);
TDatime T1(2021, 12, 01, 0, 0, 0);
int X1 = T1.Convert()-X0;
TDatime T2(2021, 12, 30, 0, 0, 0);
int X2 = T2.Convert(1)-X0;

```

‘’’

---

<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:** [April 29, 2022, 6:03am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/4 "2022-04-29T06:03:48Z")

</div>

> [@Roy](#):
>
> unix time on X-axis

What do you call “unix time” ? if that’s the number of seconds since 1970 (the standard definition) you can just use an integer. No need for a time axis.

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 29, 2022, 6:06am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/5 "2022-04-29T06:06:46Z")

</div>

Thank You,  
I tried but it changes the unix time to notation. I tried decreasing the X-axis label size but it didn’t worked.  
Is there any way to include the unix time?

---

<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:** [April 29, 2022, 6:10am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/6 "2022-04-29T06:10:16Z")

</div>

Unix time is seconds, that’s an integer how can the “unix time notation” be changed ? it is just integers. Do you have an example showing what is wrong ?

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 29, 2022, 6:22am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/7 "2022-04-29T06:22:27Z")

</div>

my range is from

```auto
    TH2F *hist = new TH2F("hist", "Current vs Time", 100, 1638338399000,1635742801000, 80, 20, 200);

```

But my Plot show as  
 ![Screen Shot 2022-04-29 at 1.22.22 AM](https://root-forum.cern.ch/uploads/default/original/3X/5/0/50e3058ae0d036ef97d0d510cefe0bc845469da5.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:** [April 29, 2022, 6:49am UTC](https://root-forum.cern.ch/t/construct-the-histogram-with-unix-time-on-x-axis/49780/8 "2022-04-29T06:49:10Z")

</div>

The order of you X limit is wrong. It should be:

```auto
 TH2D *hist = new TH2D("hist", "Current vs Time", 100, 1635742801000, 1638338399000, 80, 20, 200);

```

The value you entered are bigger than the largest integer authorised in C++. try to google “largest integer C++” . I suggest you apply an offset (substrate some fixed value) to reduce the range.
