How to show data points on a canvas

Hey all,

I have a canvas with 2 plots on it. I want to see the (x,y) coordinates of each point. Is there a way to do this via the ROOT command line or through the GUI?


Try to “activate” the option:
“your canvas” -> “main menu” -> “View” -> "Event Statusbar"
“your canvas” -> “main menu” -> “View” -> “ToolTip Info”


Thanks for the reply. This method doesn’t show precisely the (x,y) coordinate of each point, a little move on the mouse and the (x,y) values change in the status bar, is there a way to explicitly show the (x,y) coordinates next to each data point?

If you have a 1D histogram drawn, when you move the “mouse pointer” close to a drawn histogram point, you should see a line “(x=…, y=…, binx=…, binc=…, Sum=…)”.
The “binx” is the actual histogram’s “bin number” and “binc” is its “bin contents”.
Note that for a particular “binx”, you can use: TH1::GetBinLowEdge, TH1::GetBinCenter, TH1::GetBinWidth (i.e. when you move the “mouse pointer” inside of a bin you will get different “x” and “y”, but “binx” and “binc” will remain unchanged).

The 2 plots are just data points, its not a histogram.

See GetX and GetY

Im not that familiar with ROOT sorry. So If I have my canvas open with the plots, what do I type in the command line?

It is a bit vague … what are “the plots” ? My previous post assumed they are TGraph (as you said they are not histograms).

Yes they are, so if I have a canvas open with these plots, what do I type in the command line to retrieve the (x,y) coordinates? Is there even a way to do it from the command line?

Yes, you get the TGraphs from the TCanvas and then you call GetX and GetY on the TGraphs to retrieve the X and Y coordinates.

Actually mine are TGraphErrors first of all, secondly, how would I call GetX and GetY? Is this through the GUI or command line (if so, what do I type)?

Can your post the ROOT file ? Or make it available somewhere ?


   TFile *f = new TFile("PlotList_GE11_IV_Gas_Comparison_R10_21_AND_R340_352.root");
   TList *l = mGraph_Comp_GE11_IV_Gas_Comparison_canvas_Comp_GE11_IV_Gas_Comparison_timeResp-> GetListOfGraphs();
   Int_t n = l->GetSize();
   printf("Number of Graphs: %d\n", n);

   Double_t *x, *y;
   Int_t np;
   TGraph *g = (TGraph*)l->First();
   for (Int_t i = 0; i < n; i++) {
      x  = g->GetX();
      y  = g->GetY();
      np = g->GetN();
      printf("\n---\n The Points in the graph number %d are:\n",i);
      for (Int_t j=0; j<np; j++) printf("  x[%d] = %g y[%d] = %g\n", j,x[j],j,y[j]);
      g = (TGraph*)l->After(g);