Plot with extrapolation and interpolation


I have this 3 column data filedata_test.txt (274 Bytes) . I have plotted it using the following.

  TH3F *h3 = new TH3F("h3","3D",500,100,1000,500,500,1000,100,500,1000);
  for (unsigned i = 0; i < n; ++i) {
  in >> x >> y >> z;
  if (!in.good()) break;

Now I want to have extrapolation and interpolation to get a smooth surface. Is there any way to do it?

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Have you tried the option ISO ?

Hi @couet, thanks.

No, I have not.
You meant,… instead of h3->Draw(“cont4”);, I should try h3->Draw(“GLISO”); ?

or just:


See the link I sent you.

And if I want to get a parametric equation out of it, then is there any option?

That’s not Drawing . May be have a look at 3D histogram fitting.

h3->Draw(“ISO”); is creating something like this...not a colored surface.!

Yes, it is mono color. See the Help.
Try GLISO (with SetCanvasPreferGL before. See Help)
Also see if one of the examples here
matches what you are looking for.

I have tried with GLISO also, but, didn’t work.

It might be there too less points to draw a surface through them using the available floating options. May be try to do a 3D fit.

Yeah, may be because of less data points…

But, how to do a 3D fit and get an equation back?

Thanks for the link. it is running. But, When I combine this with the one I posted at the beginning of this series, it does not show up in the plot and does not give the equation as well!

//file fit3.C
#include "TRandom3.h"
#include "Riostream.h"
#include <iostream>
#include "TH3.h"
#include "TF3.h"
#include "TMath.h"
double myfunc3(double *x, double *par) {
   double xx = (x[0] - par[1])/par[2];
   double yy = (x[1] - par[3])/par[4];
   double zz = (x[2] - par[5])/par[6];
   double rx = TMath::Exp(-xx*xx);
   double ry = TMath::Exp(-yy*yy);
   double rz = TMath::Exp(-zz*zz);
   double result = par[0]*rx*ry*rz;
   return result;
void fit3() {

   const unsigned nPts1 = 15; 
   ifstream in1;"data_test.txt");

   Float_t x1,y1,z1;

   TCanvas *c1 = new TCanvas("c1"," ",0,0,700,350);

   TH3F *h1 = new TH3F("h1","h1",100,1000,3000,100,0.5,1.0,100,0.0,1.0);

      for (unsigned i = 0; i < nPts1; ++i) {
      in1 >> x1 >> y1 >> z1;
      if (!in1.good()) break;


   TF3 *func3 = new TF3("func3",myfunc3,1000,3000,0.5,1.0,0.0,1.0,7);



It gives me:

root [0] 
Processing fit3.C...
Warning in <Fit>: Fit data is empty 

do you get the same ?

I am not getting any fit.

I got that but when you run the macro do you also get the message:

Warning in <Fit>: Fit data is empty 

No…I am not getting that…:thinking:

here is the macro and the data i am using.
data_test.txt (274 Bytes) fit3.C (1.2 KB)

data_test.txt (227 Bytes)

If you test with this one, may be you can run: [please make changes correspondingly like following]

TH3F *h1 = new TH3F(“h1”,“h1”,100,1000,3000,100,0.5,1.0,100,0.0,1.0);

TF3 *func3 = new TF3(“func3”,myfunc3,1000,3000,0.5,1.0,0.0,1.0,7);