Python Forum
Problem using two-dimensional interpolation. Result looks bad
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem using two-dimensional interpolation. Result looks bad
#1
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.

Attached Files

Thumbnail(s)
       

.txt   Ydata_48_of_50.txt (Size: 19.48 KB / Downloads: 218)
.py   test3_merge1and2.py (Size: 992 bytes / Downloads: 204)
Reply
#2
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)
Reply
#3
(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

Attached Files

Thumbnail(s)
   
Reply
#4
Oops! Need to change the extent also.
extent=[23, 32, 340, 350]
Reply
#5
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to quantize a 4 dimensional array? PythonNPC 2 1,579 Apr-23-2022, 04:34 PM
Last Post: Gribouillis
  How to create 2 dimensional variables in Python? plumberpy 5 1,791 Mar-31-2022, 03:15 AM
Last Post: plumberpy
  Slicing a 2 dimensional array Scott 2 1,614 Jan-12-2022, 07:18 AM
Last Post: paul18fr
  Index data must be 1-dimensional : Classifier with sklearn Salma 0 4,261 Apr-01-2021, 03:22 PM
Last Post: Salma
  2 Dimensional Arrays Prithak 4 2,553 Mar-21-2021, 09:35 PM
Last Post: deanhystad
  programming an interpolation polynom relating newton Hallo810 1 2,166 Nov-14-2020, 03:05 PM
Last Post: buran
  comparing 2 dimensional list glennford49 10 4,037 Mar-24-2020, 05:23 PM
Last Post: saikiran
  Python 2 dimensional array creations sharpe 1 1,939 Nov-24-2019, 10:33 AM
Last Post: ThomasL
  Python: Creating N Dimensional Grid jf451 0 2,297 Dec-06-2018, 10:53 PM
Last Post: jf451
  python result problem of an iteration algorithm for power allocation Jessica 1 2,593 Sep-07-2018, 08:08 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020