[SciPy-User] 3D scatter data interpolate

gary ruben gary.ruben at gmail.com
Sat Feb 20 20:10:57 EST 2016


Hi Vasco,

Sorry for not replying sooner. I thought I had a self-contained example of
using the scipy.ndimage.map_coordinates() function to do this. I can't find
it though. It may help to look at how I used map_coordinates() to
interpolate a vector field to map the vector onto a sphere:
https://gist.github.com/gazzar/369ed55f15045bb99cae
That code is pretty old now and I don't have any small test data sets for
it, so just take a look and see if it helps,

Gary



On 16 February 2016 at 06:48, Vasco Gervasi <yellowhat46 at gmail.com> wrote:

> Hi all,
> I would like to interpolate 3D scatter data.
> I have some 3D points, each point has an associated value, I would like to
> interpolate these point to calculate the value of a random point.
> This example may help to understand:
>
>> from math import cos, sin
>> from scipy.interpolate import Rbf
>> from numpy import linspace, pi
>> from mpl_toolkits.mplot3d import Axes3D
>> import matplotlib.pyplot as plt
>> #%% Data
>> R = 10.0
>> x = list()
>> y = list()
>> z = list()
>> c = list()
>> for i in linspace(0.0,10.0,11):
>>     for t in linspace(0.0,2*pi,90):
>>         x.append(R*cos(t))
>>         y.append(R*sin(t))
>>         z.append(i)
>>         c.append(i)
>> #%% Plot
>> fig = plt.figure()
>> ax = fig.add_subplot(111, projection='3d')
>> sc = ax.scatter(x, y, z, c=z)
>> ax.set_xlabel('X')
>> ax.set_ylabel('Y')
>> ax.set_zlabel('Z')
>> plt.colorbar(sc)
>> #%%
>> rbfi = Rbf(x, y, z, c)
>> xi = [0,0]
>> yi = [0,0]
>> zi = [0,1]
>> print rbfi(xi, yi, zi)
>
> As you can see here we have some points over a cylinder, each point has
> associate a value (color), which in this case is the z-coordinate.
> scipy.interpolate.Rbf should answer my problem, to better understsand how
> it works I gave it some points [[0,0,0],[0,0,1]], but the result of
> rbfi(xi, yi, zi) is [-1.04833984 -0.10205078].
> I expected that a point along the axis, aligned with some point should
> return the z-coordinate of this point [0, 1] but got some negative number.
> Any ideas?
> Do you have any alternative that I can use to have a linear interpolation
> or by the nearest?
>
> Thanks
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> https://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20160221/a1b39da6/attachment.html>


More information about the SciPy-User mailing list