Python Forum

Full Version: Problem using two-dimensional interpolation. Result looks bad
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone. I am following this tutorial (at 04:57) to construct two-dimensional interpolation using Radial basis functions. I have constructed the following code:


newfunc=interpolate.Rbf(resulttokenX2.astype('float'), resulttokenY2.astype('float'), resulttokenF2.astype('float'), function='multiquadric')
xnew, ynew=np.mgrid[340:350:100j, 23:32:100j]
fnew=newfunc(xnew, ynew)

#create image plot
py.figure(1)
py.clf()
py.imshow(fnew, extent=[340, 350, 23, 32], cmap=py.cm.jet)
However, the resulting image is shifted.

This is what I get: [Image: KK92CQrr]

And this is what it should be: [Image: grLWBVw8]

I have used paint to turn left the original result to arrive to the previous figure.

Can someone please tell me what I have to do to arrive to the second figure instead of the first? I have tried changing the values inside of
np.mgrid
, but I haven't achieved any result.

I will attach the data and my full code just in case someone wants to take a look.

Best regards.
Player1682.

Note: since the links to the images seem broken, I will attach them too.
I suggest you find a more recent tutorial. From scipy documentation for interpolate.Rbf

https://docs.scipy.org/doc/scipy/referen...e.Rbf.html
Quote:Rbf is legacy code, for new usage please use RBFInterpolator instead.
It looks like you want change the axes for you plot. Try this:
fnew=newfunc(ynew, xnew)
(Oct-11-2021, 03:05 PM)deanhystad Wrote: [ -> ]I suggest you find a more recent tutorial. From scipy documentation for interpolate.Rbf

https://docs.scipy.org/doc/scipy/referen...e.Rbf.html
Quote:Rbf is legacy code, for new usage please use RBFInterpolator instead.
It looks like you want change the axes for you plot. Try this:
fnew=newfunc(ynew, xnew)

Thanks for the advice I will start reading documentation on interpolate.Rbf.

I have tried swithching X and Y as you suggest. I get the attached figure. It has to be something else. I hope it has to do with the obsolete code.

Edit:

newfunc=scipy.interpolate.Rbf(resulttokenX2.astype('float'), resulttokenY2.astype('float'), resulttokenF2.astype('float'), function='linear')
returns the same values
Oops! Need to change the extent also.
extent=[23, 32, 340, 350]
(Oct-11-2021, 03:26 PM)deanhystad Wrote: [ -> ]Oops! Need to change the extent also.
extent=[23, 32, 340, 350]

I'm afraid that's not it either. I thing it has to do with the fact that X values are stored from low to high and Y are from high to low.

EDIT: In the end I have managed to fix it flipping the data of resulltokenY and also the axis, as your last message sugested.

Thanks.