Dear ROOT experts,
I experience a strange issue when drawing multiple TH2F histograms with contours (draw option "CONT LIST"
) onto a canvas with grid lines:
-
I create a canvas with grid lines.
-
I draw a TH2F histogram via
h->Draw("CONT LIST");
clone and manipulate it’s contour lines and draw them -
I draw another TH2F histogram via
h->Draw("CONT LIST SAME");
clone and manipulate it’s contour lines and draw them
The strange effect is that the contour graphs of the second histogram (drawn with the SAME option) hide the grid lines, while the contour graphs of the first histogram don’t.
Here is a code snipped which reproduces this issue
void drawContours(Style_t style)
{
gPad->Update();
TObjArray* contours = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
if (!contours) {
std::cout << "Error: no contours created" << std::endl;
return;
}
if (contours->GetSize() > 1)
std::cout << "Warning: more that 1 contour created" << std::endl;
TList* list = (TList*)contours->First();
if (!list) {
std::cout << "Error: first contour is empty" << std::endl;
return;
}
for (Int_t i = 0; i < list->GetSize(); ++i) {
TGraph* graph = (TGraph*)list->At(i);
if (!graph) continue;
TGraph* clonedGraph = (TGraph*)graph->Clone();
clonedGraph->SetLineStyle(style);
clonedGraph->Draw("L");
}
}
contourFill()
{
gStyle->Reset();
TCanvas *c = new TCanvas("c", "c", 1000, 500);
c->SetGrid();
TH2F* h = new TH2F("h", "h", 50, -5, 5, 50, -5, 5);
h->FillRandom("gaus", 100000);
h->SetContour(1, new Double_t(1));
h->Draw("CONT LIST");
drawContours(1);
TH2F* h2 = new TH2F("h2", "h2", 50, -5, 5, 50, -5, 5);
h2->FillRandom("gaus", 100000);
h2->SetContour(1, new Double_t(10));
h2->Draw("CONT LIST SAME");
drawContours(2); // these contours hide the grid
}
How can I forbid the contour graphs to hide the grid lines?
Many thanks in advance,
Alexander Voigt