Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
candleplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Example of candle plot with 2-D histograms.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Georg Troska
10 
11 void candleplot() {
12 
13  gStyle->SetTimeOffset(0);
14  TDatime dateBegin(2010,1,1,0,0,0);
15  TDatime dateEnd(2011,1,1,0,0,0);
16 
17  auto h1 = new TH2I("h1","Machine A + B",12,dateBegin.Convert(),dateEnd.Convert(),1000,0,1000);
18  auto h2 = new TH2I("h2","Machine B",12,dateBegin.Convert(),dateEnd.Convert(),1000,0,1000);
19 
20  h1->GetXaxis()->SetTimeDisplay(1);
21  h1->GetXaxis()->SetTimeFormat("%m/%y");
22  h1->GetXaxis()->SetTitle("Date [month/year]");
23 
24  float Rand;
25  for (int i = dateBegin.Convert(); i < dateEnd.Convert(); i+=86400*30) {
26  for (int j = 0; j < 1000; j++) {
27  Rand = gRandom->Gaus(500+sin(i/10000000.)*100,50); h1->Fill(i,Rand);
28  Rand = gRandom->Gaus(500+sin(i/11000000.)*100,70); h2->Fill(i,Rand);
29  }
30  }
31 
32  h1->SetBarWidth(0.4);
33  h1->SetBarOffset(-0.25);
34  h1->SetFillColor(kYellow);
35  h1->SetFillStyle(1001);
36 
37  h2->SetBarWidth(0.4);
38  h2->SetBarOffset(0.25);
39  h2->SetLineColor(kRed);
40  h2->SetFillColor(kGreen);
41 
42  auto c1 = new TCanvas();
43 
44  h1->Draw("candle2");
45  h2->Draw("candle3 same");
46 
47  gPad->BuildLegend(0.78,0.695,0.980,0.935,"","f");
48 }