# How to make visible a single point on a 3d surface plot

**URL:** <https://root-forum.cern.ch/t/how-to-make-visible-a-single-point-on-a-3d-surface-plot/59608>\
**Category:** Newbie\
**Tags:** graphics\
**Created:** [June 10, 2024, 3:20pm UTC](https://root-forum.cern.ch/t/how-to-make-visible-a-single-point-on-a-3d-surface-plot/59608 "2024-06-10T15:20:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas\_Peron](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lukas_peron/32/36757_2.png) [@Lukas\_Peron](https://root-forum.cern.ch/u/Lukas_Peron)\
**Post date:** [June 10, 2024, 3:20pm UTC](https://root-forum.cern.ch/t/how-to-make-visible-a-single-point-on-a-3d-surface-plot/59608/1 "2024-06-10T15:20:57Z")

</div>

Hi everyone.

Is it possible to add a specific point to a 3d plot so its clearly visible like this example (done with python) ?  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/b/5/b574e65110d1eb0804dc7809f2b244b2ae9bb78b.png)

I’d like to add the minimum found by a gradient descent algorithm for a function and make it clearly visible on the plot. Here’s my code :

```auto
int main() {
    std::vector<double> initialGuess = {3,4};
    std::vector <double> min = gradientDescent(initialGuess, exampleFunction);
    // Create a 3D graph
    TGraph2D *graph = new TGraph2D();
    TGraph2D *graph2 = new TGraph2D();

    // Fill the graph with points from the function
    for (double x = -2; x <= 2; x += 0.1) {
        for (double y = -2; y <= 2; y += 0.1) {
            double z = exampleFunction({x, y});
            graph->SetPoint(graph->GetN(), x, y, z);
        }
    }
    
    // Add the minimum point to the graph
    graph2->SetPoint(0, min[0], min[1], min[2]);
    graph2->SetMarkerColor(kRed);
    graph2->SetMarkerStyle(20);
    // Create a canvas to display the 3D plot
    TCanvas *canvas = new TCanvas("canvas", "3D Plot", 800, 600);
    graph2->Draw("p");
    graph->Draw("surf1");
    return 0;
}

```

Thanks in advance 🙂  
Lukas.

* * *

_ROOT Version:_ 6.30/04

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [June 10, 2024, 11:26pm UTC](https://root-forum.cern.ch/t/how-to-make-visible-a-single-point-on-a-3d-surface-plot/59608/2 "2024-06-10T23:26:15Z")

</div>

Create and draw (after drawing your TGraph2D) a [TPolyMarker3D](https://root.cern/doc/master/classTPolyMarker3D.html) containing one point with the coordinates where you want it. See an example in [this tutorial](https://root.cern/doc/master/basic3d_8C.html).

---

<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:** [June 11, 2024, 6:34am UTC](https://root-forum.cern.ch/t/how-to-make-visible-a-single-point-on-a-3d-surface-plot/59608/3 "2024-06-11T06:34:04Z")

</div>

Your approach might work but you need to do:

```auto
    graph->Draw("surf1");
    graph2->Draw("p same");

```

---

<div class="post-metadata">

**Author:** ![Lukas\_Peron](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lukas_peron/32/36757_2.png) [@Lukas\_Peron](https://root-forum.cern.ch/u/Lukas_Peron)\
**Post date:** [June 11, 2024, 7:05am UTC](https://root-forum.cern.ch/t/how-to-make-visible-a-single-point-on-a-3d-surface-plot/59608/4 "2024-06-11T07:05:06Z")

</div>

It works, thanks a lot !
