Adding 2D curve to a 3D plot

Hello all,

is it possible to add 2D curves to a 3D plot.

Please see the two gifs I have attacted…the 2D plot has a red circle on it which I would like to have plotted on the 2D projection in the 3D plot.

Can this be done?

Cheers

TF2 is what you need.

Here is a small example showing how to superimpose 3D lines on a 3D surface:

``````{
int NBins = 50;
double d = 2;

TH2F* h2 = new TH2F("h2", "h2", NBins, -d, d, NBins, -d, d);
for (int bx = 1;  bx <= NBins; ++bx) {
for (int by = 1;  by <= NBins; ++by) {
double x = h2->GetXaxis()->GetBinCenter(bx);
double y = h2->GetYaxis()->GetBinCenter(by);
h2->SetBinContent(bx, by, exp(-x*x)*exp(-y*y));
}
}

TCanvas *c1=new TCanvas("c1","c1",600,600);
h2->Draw("surf4");

int LineBins = 100;
TPolyLine3D *l = 0;
for (double h = 0; h < 0.9*d; h+= d/20.0) {
l = new TPolyLine3D(LineBins);
for (int e = 0; e < LineBins; ++e) {
Double_t Angle = e*2*TMath::Pi()/LineBins;
l->SetPoint(e, h*cos(Angle), h*sin(Angle), exp(-h*h));
}
l->SetLineColor(2);
l->Draw("SAME");
}

c1->Update();
}``````

wow…just what I was looking for.

Thanks