Zooming in the multigraph

I have read some data from a CSV file and then plotted it with the TMultiGraph command. The graph that I obtained looks like this:

I would like to be able to zoom in on specific parts of the graph and read values off. I would like if the graph would look more like this:


I have ofcourse tried to look into the documentation of TGraphPainter but I have been unable to find something there. Is there some way to achieve this?

You can adjust the axis limit of the TMultigraph using multiGraph->GetXaxis()->SetRangeUser(low, high);

Example:

auto mg = new TMultiGraph();
auto g1 = new TGraph();
auto static random3 = new TRandom3();
for (int i = 0; i < 100; i++)
{
   g1->SetPoint(i, (double) i, random3->Rndm() * 10);
}
mg->Add(g1);
mg->Draw("AL");
mg->GetXaxis()->SetRangeUser(5, 34);

If you want access to the y-values, you can call g1->Eval(x); on a single TGraph, but you first need to get the underlying graph from the TMultiGraph. Eval uses a linear interpolation between points (so just like the lines drawn).

If you want to do this for the ith graph, you can do:

static_cast<TGraph *>(mg->GetListOfGraphs()->At(i))->Eval(x);

or

((TGraph *) mg->GetListOfGraphs()->At(i))->Eval(x);
1 Like

Upon using the command you suggested, I managed to produce the following picture:

Now, my problem with this is that on a very small scale, all the lines are black, instead of the colours I assigned to them via the command gr->SetMarkerColor(number). Is this due to the processes involved in uniting the points that I read from the file? Is there some way to make them different?

I don’t know what procedure you used for that.

However, it seems like you need to set the line color in addition to the marker color (if you draw your TMultiGraph with option Draw("AL") for example). Use TGraph::SetLineColor() on the individual graphs before adding them to the multi graph.

Alternatively, draw the multi graph with the options Draw("A PMC PLC"), which automtically picks the next color from the current palette for the marker ("PMC") and the line ("PLC"), as documented here: https://root.cern.ch/doc/master/classTGraphPainter.html#GP05 (only available since ROOT 6.09.01).

2 Likes

Thank you for your answer. Now it works

You may also want to investigate TPad::SetCrosshair, TCanvas::ToggleEventStatus, and TCanvas::ToggleToolTips.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.