How to draw multiple surfaces with intersections?

Hello!
I need to draw two surfaces on the same canvas, namely TGraph2D with TRI1 option and its fit with TF2 with SURF1 option.
I made very simple example:

{
  TF2 f1("f1", "x^2 + y^2", -3, 3, -3, 3);
  TF2 f2("f2", "x + y + 5", -3, 3, -3, 3);
  f1.Draw("surf1");
  f2.Draw("surf1 same");
  
  f1.SetMinimum(0.0);
  f1.SetMaximum(18.0);
  f2.SetMinimum(0.0);
  f2.SetMaximum(18.0);
}

However, I get this:

Currently I have to export data to Octave, where I can get nice plots like this:


where I can clearly see if fitted surface matches data.

Is there any way to draw multiple surfaces properly in ROOT?


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.26/06
Platform: CentOS 7 x86_64
Compiler: gcc (GCC) 12.2.0


void ako()
{
  auto f1 = new TF2("f1", "x^2 + y^2", -3, 3, -3, 3);
  auto f2 = new TF2("f2", "x + y + 5", -3, 3, -3, 3);

  f1->SetMinimum(0.0);
  f1->SetMaximum(18.0);
  f2->SetMinimum(0.0);
  f2->SetMaximum(18.0);
  f2->Draw("surf1");
  f1->Draw("surf1 same");

}

Thanks for your response, @couet! My apologies, probably my first example is a bit misleading. Here’s a more obvious one.

void ako()
{
  TF2 f1("f1", "x - y + 5", -3, 3, -3, 3);
  TF2 f2("f2", "x + y + 5", -3, 3, -3, 3);

  
  f1.SetMinimum(0.0);
  f1.SetMaximum(10.0);
  f2.SetMinimum(0.0);
  f2.SetMaximum(10.0);

  f1.Draw("surf1");
  f2.Draw("surf1 same");
}

What I get vs what I expect:

I mean, seems like order of Draw calls doesn’t matter here. Am I missing some simple option?

Ah yes, this will not work. The two surfaces ignore each other.
May have a look at ROOT: THistPainter Class Reference
And the GL option after.

1 Like

Sorry for late reply.
Using TGLHistPainter produces same behavior, and it seems that SAME option doesn’t work properly.

void ako() {
  gStyle->SetCanvasPreferGL(true);

  TF2 f1("f1", "x - y + 5", -3, 3, -3, 3);
  TF2 f2("f2", "x + y + 5", -3, 3, -3, 3);
  
  f1.SetMinimum(0.0);
  f1.SetMaximum(10.0);
  f2.SetMinimum(0.0);
  f2.SetMaximum(10.0);

  f1.Draw("glsurf1");
  f2.Draw("glsurf1 same");
}

Regarding TF3, I’ve managed to get sensible result with this approach:

{
  auto f3 = new TF3("f3","(x - y + 5 - z) * (x + y + 5 - z)",-3,3,-3,3,-2,12);
  f3->SetFillColor(30);
  f3->SetLineColor(15);
  f3->SetNpz(100);
  f3->Draw("fb bb");
}


However, it’s not clear how to apply it to my case of visual comparison of TGraph2D and its fit with TF2. I need to convert TGraph2D into implicit 3d function somehow.

So far, I will just continue to use Octave as simplest solution.
Anyway, thank you for help!

With TGraph2D you cannot have surfaces with several z values for one (x,y) pair.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.