# How to show the coordinates of a 3D graph

**URL:** <https://root-forum.cern.ch/t/how-to-show-the-coordinates-of-a-3d-graph/54688>\
**Category:** Newbie\
**Tags:** graphics, root\
**Created:** [May 1, 2023, 5:04pm UTC](https://root-forum.cern.ch/t/how-to-show-the-coordinates-of-a-3d-graph/54688 "2023-05-01T17:04:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrapo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/da6949/32.png) [@rrapo](https://root-forum.cern.ch/u/rrapo)\
**Post date:** [May 1, 2023, 5:04pm UTC](https://root-forum.cern.ch/t/how-to-show-the-coordinates-of-a-3d-graph/54688/1 "2023-05-01T17:04:58Z")

</div>

_ROOT Version:_ 6.26/06  
_Compiler:_ macOS

Hi! i have been working on a 3D plot.  
I have no issue with the plot (I’m attaching the c file and its txt file).

But I’d like to show the coordinates of the points on the graph.

I think I can do something horrible like making many little legends which have the coordinates and moving these to points, but I’m hoping there is a better way to do it.

I hope you can help me,  
thanks for the time wasted for me!

[magnetizzazione.C](https://root-forum.cern.ch/uploads/short-url/4ZxB1ibVZJsG1iSKvycu9WdreY7.C) (1.2 KB)  
[plot3Di.txt](https://root-forum.cern.ch/uploads/short-url/AhWl3OPsO1ANU2mZbscBRnYLAcK.txt) (300 Bytes)  
)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 2, 2023, 8:55am UTC](https://root-forum.cern.ch/t/how-to-show-the-coordinates-of-a-3d-graph/54688/3 "2023-05-02T08:55:54Z")

</div>

Indeed Text3D is missing forwhat you want to do.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 2, 2023, 2:16pm UTC](https://root-forum.cern.ch/t/how-to-show-the-coordinates-of-a-3d-graph/54688/4 "2023-05-02T14:16:14Z")

</div>

```auto
void magnetizzazione(){
   TGraph2D *graph1 = new TGraph2D("plot3Di.txt");
   graph1->SetTitle("mappa del campo magnetico; larghezza (cm); altezza(cm); B (mT)");
   gStyle->SetPalette(1);
   graph1->SetMarkerStyle(20);
   gStyle->SetHistTopMargin(0);
   graph1->Draw("surf1");

   TGraph2D *graph = new TGraph2D("plot3Di.txt");
   graph->SetMarkerColor(kBlack);
   graph->SetMarkerStyle(20);
   graph->Draw("SAME P0");

   gPad->Update();

   TView *view = gPad->GetView();
   if (!view) return;

   int n = graph->GetN();
   double x,y,z;
   double xyz[3];
   for (int i=1; i<n; i++) {
      graph->GetPoint(i,x,y,z);
      xyz[0] = x;
      xyz[1] = y;
      xyz[2] = z;
      Double_t xpad[3];
      view->WCtoNDC(xyz, &xpad[0]);

      auto l = new TLatex(xpad[0],xpad[1]+0.02,Form("(%4.2f, %4.2f, %4.2f)",x,y,z));
      l->SetTextSize(0.02);
      l->SetTextFont(42);
      l->SetTextAlign(21);
      l->Draw();
   }
}

```

 ![Screenshot 2023-05-02 at 16.14.47](https://root-forum.cern.ch/uploads/default/original/3X/8/3/83f51087885d55fa65c339e172ce74b77973069b.jpeg)

---

<div class="post-metadata">

**Author:** ![rrapo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/da6949/32.png) [@rrapo](https://root-forum.cern.ch/u/rrapo)\
**Post date:** [May 3, 2023, 8:08am UTC](https://root-forum.cern.ch/t/how-to-show-the-coordinates-of-a-3d-graph/54688/5 "2023-05-03T08:08:45Z")

</div>

Oh! Thank you so much!  
Have a nice day!

Rrapo
