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

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

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 :

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 :slight_smile:
Lukas.


ROOT Version: 6.30/04


Create and draw (after drawing your TGraph2D) a TPolyMarker3D containing one point with the coordinates where you want it. See an example in this tutorial.

Your approach might work but you need to do:

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

It works, thanks a lot !