Hello! I am having a bit of trouble with painting grid on my plot. Here’s the example that reproduces what I am trying to show:
void draw_line_graphs() {
TCanvas* c = new TCanvas("c", "Line Graphs Canvas", 800, 600);
c->SetGrid();
gStyle->SetGridColor(kGray);
TMultiGraph* mg = new TMultiGraph();
const int n_points = 100;
double x1[n_points], y1[n_points];
TRandom rand;
for (int i = 0; i < n_points; ++i) {
x1[i] = i;
y1[i] = rand.Gaus(5, 2);
}
TGraph* graph1 = new TGraph(n_points, x1, y1);
graph1->SetTitle("Graph 1");
graph1->SetLineColor(kRed);
graph1->SetLineWidth(2);
double x2[n_points], y2[n_points];
for (int i = 0; i < n_points; ++i) {
x2[i] = i;
y2[i] = rand.Gaus(10, 3);
}
TGraph* graph2 = new TGraph(n_points, x2, y2);
graph2->SetTitle("Graph 2");
graph2->SetLineColor(kBlue);
graph2->SetLineWidth(2);
mg->Add(graph1, "L");
mg->Add(graph2, "L");
mg->SetTitle("MultiGraph with Line Graphs;X axis;Y axis");
mg->Draw("A");
mg->SetMaximum(16);
mg->GetXaxis()->SetLimits(0, 100);
c->Update();
c->SaveAs("line_graphs.pdf");
}
My goal here is to set plot’s limits so that they are not managed automatically, but rather take predetermined value (be it from any func, or I just set it myself). And I also need grey grid, because it’s fancier and it’s exactly what I need. However, when I set limits for x and y myself, the top and right border of my plot get overlapped by grey grid:
I haven’t found any methods or functionality that dictates the order of drawing for grids and borders. I see this as either changing the drawing order, so that grid is somehow “under” the border, or manually changing color of exactly the top and the most right grid dot row.
I would appreciate any help that would solve this issue!
A little bit of follow-up, I’ve just noticed, that redrawing the axis also draws on top of existing TGraphs, which is a bit of an issue, since my lowest values often go to zero, and it is also where the lower limit of Y axis is located (intentionally). I am fine with data being on top of axis, but redrawing axis puts data behind them. Perhaps there’s a way to invoke the redrawing of TGraphs?
Please, ignore the fact that data line is currently wider, my goal is to have red line on top of the black axis AND have proper display of grey grid (under the black axis)