ROOT logo

From $ROOTSYS/tutorials/graphs/timeonaxis2.C

void timeonaxis2() {
   // Define the time offset as 2003, January 1st
   //Author: Olivier Couet
   
   TDatime T0(2003,01,01,00,00,00);
   int X0 = T0.Convert();
   gStyle->SetTimeOffset(X0);
   
   // Define the lowest histogram limit as 2002, September 23rd
   TDatime T1(2002,09,23,00,00,00);
   int X1 = T1.Convert()-X0;

   // Define the highest histogram limit as 2003, March 7th
   TDatime T2(2003,03,07,00,00,00);
   int X2 = T2.Convert(1)-X0;

   TH1F * h1 = new TH1F("h1","test",100,X1,X2);      

   TRandom r;
   for (Int_t i=0;i<30000;i++) {
      Double_t noise = r.Gaus(0.5*(X1+X2),0.1*(X2-X1));
      h1->Fill(noise);
   }
   
   h1->GetXaxis()->SetTimeDisplay(1);
   h1->GetXaxis()->SetLabelSize(0.03);
   h1->GetXaxis()->SetTimeFormat("%Y\/%m\/%d");
   h1->Draw();
}
 timeonaxis2.C:1
 timeonaxis2.C:2
 timeonaxis2.C:3
 timeonaxis2.C:4
 timeonaxis2.C:5
 timeonaxis2.C:6
 timeonaxis2.C:7
 timeonaxis2.C:8
 timeonaxis2.C:9
 timeonaxis2.C:10
 timeonaxis2.C:11
 timeonaxis2.C:12
 timeonaxis2.C:13
 timeonaxis2.C:14
 timeonaxis2.C:15
 timeonaxis2.C:16
 timeonaxis2.C:17
 timeonaxis2.C:18
 timeonaxis2.C:19
 timeonaxis2.C:20
 timeonaxis2.C:21
 timeonaxis2.C:22
 timeonaxis2.C:23
 timeonaxis2.C:24
 timeonaxis2.C:25
 timeonaxis2.C:26
 timeonaxis2.C:27
 timeonaxis2.C:28
 timeonaxis2.C:29
 timeonaxis2.C:30