Hi, it’s a while ago I implemented this…
TCandle is a painter-class, so you cannot access the properties of the candles immediately (TCandle is only used by THistPainter directly), we did something in the past, by using these global variables, as suggested by @couet
Today you can represent the mean of the candle by using a dashed line (please refer to THistPainter-Doc). The candle enforces the line to be dashed in order to give a consistent candle behaviour inside root. By doing so one can always differentiate between the median (non-dashed) and the mean (dashed, or circle).
Nevertheless, I have a cheat (or two) for you. I already mentioned this in post before, you can tell root to create an individual candle by createing histoslides with exact 5 values, due to the calculation method (basically it is the GetQuantiles-Function of TH1) these will represent, mean, the box-ranges and the anchors. I just tested this new cheat for you
void candleplot() {
gStyle->SetTimeOffset(0);
TDatime dateBegin(2010,1,1,0,0,0);
TDatime dateEnd(2011,1,1,0,0,0);
auto h1 = new TH2I("h1","Machine A + B",12,dateBegin.Convert(),dateEnd.Convert(),1000,0,1000);
auto h1mean = new TH2I("h1mean","Mean of Machine A + B",12,dateBegin.Convert(),dateEnd.Convert(),1000,0,1000);
auto h2 = new TH2I("h2","Machine B",12,dateBegin.Convert(),dateEnd.Convert(),1000,0,1000);
auto h2mean = new TH2I("h2mean","Mean of Machine B",12,dateBegin.Convert(),dateEnd.Convert(),1000,0,1000);
h1->GetXaxis()->SetTimeDisplay(1);
h1->GetXaxis()->SetTimeFormat("%m/%y");
h1->GetXaxis()->SetTitle("Date [month/year]");
float Rand;
for (int i = dateBegin.Convert(); i < dateEnd.Convert(); i+=86400*30) {
for (int j = 0; j < 1000; j++) {
Rand = gRandom->Gaus(500+sin(i/10000000.)*100,50); h1->Fill(i,Rand);
Rand = gRandom->Gaus(500+sin(i/11000000.)*100,70); h2->Fill(i,Rand);
}
}
for (int i = 1; i <= h2->GetXaxis()->GetNbins(); i++) {
TH1D *hSlice = h1->ProjectionY("_py",i,i+1);
float meanOfSlice = hSlice->GetMean();
h1mean->Fill(h2->GetXaxis()->GetBinCenter(i), meanOfSlice);
hSlice = h2->ProjectionY("_py",i,i+1);
meanOfSlice = hSlice->GetMean();
h2mean->Fill(h2->GetXaxis()->GetBinCenter(i), meanOfSlice);
}
h1->SetBarWidth(0.4);
h1->SetBarOffset(-0.25);
h1->SetFillColor(kYellow);
h1->SetFillStyle(1001);
h1mean->SetBarWidth(0.4);
h1mean->SetBarOffset(-0.25);
h2->SetBarWidth(0.4);
h2->SetBarOffset(0.25);
h2->SetMarkerStyle(106);
h2->SetLineColor(kRed);
h2->SetFillColor(kGreen);
h2mean->SetBarWidth(0.4);
h2mean->SetBarOffset(0.25);
h2mean->SetLineColor(kRed);
h2mean->SetLineWidth(5);
auto c1 = new TCanvas();
h1->Draw("candle(112001)"); //1=outliers, 1=anchor, 2=whisker at 1.5iqr, 0=no mean, 0=no median, 1=box
h1mean->Draw("candle(200000) same"); //draw all values as cross
h2->Draw("candle(112001) same"); //1=outliers, 1=anchor, 2=whisker at 1.5iqr, 0=no mean, 0=no median, 1=box
h2mean->Draw("candle(10000) same"); //drawing only the anchors
gPad->BuildLegend(0.78,0.695,0.980,0.935,"","f");
}
I’m creating two new histos h1mean and h2mean which only contain the mean values per candle-slice.
I changed the drawing method for h1, so that the candle will not draw the mean anymore, instead of this we are drawing the mean by using h1mean on top of this. h1mean uses the “draw all values”, as only mean is inside, it will be drawn. Unluckily, TCandle enforces us that the values are drawn as crosses (that would be a nice improvement).
In the second case, h2mean is drawn on top of h2, and here we are drawing only the anchors. As there is only one value inside, the anchor will have the value of the mean.
There is a pretty good documentiation about the candle-options in THistPainter-Doc,
Hope this helps
@couet:
Instead of the original change-request I would rather recommend a global variable containing the markeroption for the outliers (in case you want to draw all datapoints)
Georg