Label Points on Log-Log graph

So I’m trying to use Root to graph a bunch of functions and points, and then label these points. I’m following the graphtext.C example (cannot link to it due to new user restrictions), but my labels don’t seem to be showing up at all.

I suspect that I might be running into an issue between user coordinates and the large scale of my data (moreover, I’m using log axes). When I try to paint the labels using NCD coordinates they show up fine, but converting from user coordinates to NCD coordinates seems to be discouraged, and moreover it’s pretty difficult and tedious to hunt for the correct scaling factors.

Here is a SCCE that avoids some of the complixities of plotting a whole bunch of curves and finding the proper graph buried in the multigraph. Just trying to label some points on a log-log graph and failing.

void drawtext() {
  int i,n;
  double x,y;

  TText t;
  t.SetTextAlign(13);
  t.SetTextColor(kBlue);
  t.SetTextFont(43);
  t.SetTextSize(10000); // I don't know where the limit is, but much larger than this results in an error

  auto g = (TGraph*)gPad->GetPrimitive("Points");

  n = g->GetN();

  const char * labels[] = {"Reactor", "Experiment (torus)", "Experiment (pinch)", "Ionosphere", "Radiofreq plasma", "Flame", "Laser", "Space"};

  for (i=0; i<n; i++) {
    g->GetPoint(i,x,y);
    t.PaintText(x, y, labels[i]);
  }
}

void scce() {
  const double xmin = 1e6;
  const double xmax = 1e28;

  const double ymin = 1e-2;
  const double ymax = 1e5;

  auto cv = new TCanvas("cv", "cv", 1920, 1200);
  cv->SetLogx();
  cv->SetLogy();
  cv->SetGrid();

  // plasma points
  const int point_count = 8;
  const double ns[point_count] = {1e20, 1e19, 1e23, 1e11, 1e17, 1e14, 1e25, 1e6};
  const double ts[point_count] = {3e4, 100, 1000, 0.05, 1.5, 0.1, 100, 0.01};
  auto *g_points = new TGraph();
  g_points->SetName("Points");

  auto ex = new TExec("ex", "drawtext();");
  g_points->GetListOfFunctions()->Add(ex);

  g_points->SetTitle("Various Example Plasmas");
  g_points->SetMarkerStyle(20);
  for (int i = 0; i < point_count; ++i) {
    g_points->SetPoint(i, ns[i], ts[i]);
  }
  g_points->GetXaxis()->SetLimits(xmin, xmax);
  g_points->SetMinimum(ymin);
  g_points->SetMaximum(ymax);
  g_points->Draw("AP");
}

Note: I have also tried taking the log10 of both x and y before drawing the text, but that doesn’t seem to affect things.


ROOT Version: 6.24/06
Platform: Linux
Compiler: GCC 11.3.0


Why 10000? For font precision 3 (as in 43, in your case) this size is in pixels. Try 10 and go from there.

I tried a number of different sizes. I started with smaller sizes, such as 10 and 20, but I went bigger so that if the text was printing anywhere remotely near to the canvas area it would show up.

Also the example graphtext.C used text size 0.025 (but perhaps a different font precision, I don’t recall, and I’ve been mucking around with the exact text settings a lot) and through trial and error I determined in that particular situation it was related to the user coordinate size, so I figured because my user coordinates are very large I would also need a very large font size.

Either way setting the font size to 10 does not help, but thanks for the documentation reference.

Please excuse me. Apparently, I spoke too soon. I don’t know exactly what I tested before, but that particular combination seems to work as expected. And I feel… actually kinda dumb now. Thanks.