Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist049_Graphics_candle_plot.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 (tcanvas_js)
7/// \macro_code
8///
9/// \date May 2024
10/// \author Georg Troska
11
13{
14
16 TDatime dateBegin(2010, 1, 1, 0, 0, 0);
17 TDatime dateEnd(2011, 1, 1, 0, 0, 0);
18
19 auto h1 = new TH2I("h1", "Machine A + B", 12, dateBegin.Convert(), dateEnd.Convert(), 1000, 0, 1000);
20 auto h2 = new TH2I("h2", "Machine B", 12, dateBegin.Convert(), dateEnd.Convert(), 1000, 0, 1000);
21
23 h1->GetXaxis()->SetTimeFormat("%d/%m/%y");
25 h1->GetXaxis()->SetTitle("Date [day/month/year]");
26
27 float Rand;
28 for (int i = dateBegin.Convert(); i < dateEnd.Convert(); i += 86400 * 30) {
29 for (int j = 0; j < 1000; j++) {
30 Rand = gRandom->Gaus(500 + sin(i / 10000000.) * 100, 50);
31 h1->Fill(i, Rand);
32 Rand = gRandom->Gaus(500 + sin(i / 11000000.) * 100, 70);
33 h2->Fill(i, Rand);
34 }
35 }
36
37 h1->SetBarWidth(0.4);
38 h1->SetBarOffset(-0.25);
40 h1->SetFillStyle(1001);
41
42 h2->SetBarWidth(0.4);
43 h2->SetBarOffset(0.25);
44 h2->SetLineColor(kRed);
45 h2->SetFillColor(kGreen);
46
47 auto c1 = new TCanvas();
48
49 h1->Draw("candle2");
50 h2->Draw("candle3 same");
51
52 gPad->BuildLegend(0.78, 0.695, 0.980, 0.935, "", "f");
53}
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition TAttAxis.cxx:233
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:40
virtual void SetTimeDisplay(Int_t value)
Definition TAxis.h:173
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition TAxis.cxx:1159
The Canvas class.
Definition TCanvas.h:23
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
virtual void SetBarOffset(Float_t offset=0.25)
Set the bar offset as fraction of the bin width for drawing mode "B".
Definition TH1.h:380
TAxis * GetXaxis()
Definition TH1.h:340
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
virtual void SetBarWidth(Float_t width=0.5)
Set the width of bars as fraction of the bin width for drawing mode "B".
Definition TH1.h:381
2-D histogram with an int per channel (see TH1 documentation)
Definition TH2.h:227
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:275
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition TStyle.cxx:1915
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5