matlab与⽹格,matlab⽹格⽹格的使⽤
以下措施应该有效:numcols, numrows = 300, 300
xi = np.linspace(data.Lon.min(), data.Lon.max(), numrows)
linspace numpyyi = np.linspace(data.Lat.min(), data.Lat.max(), numcols)
xi, yi = np.meshgrid(xi, yi)
x, y, z = data.Lon.values, data.Lat.values, data.Z.values
points = np.vstack((x,y)).T
values = z
wanted = (xi, yi)
zi = griddata(points, values, wanted)
最后⼀⾏是griddata的⼯作原理(假设您使⽤iddata?)
你的问题是你似乎给了griddata五个参数,⽽如果我看⼀下{a1},它会说:
^{pr2}$
所以在你的例⼦中,给出五个参数是错误的地⽅(如果你这样做,请确认它是否有效,因为我没有你的数据,所以我⽆法测试它是否给出正确的结果)。在
所以在你的例⼦中,已知值的点是x,⽽在那⼀点已知的值是y值,你想知道它们的点是z值。不知道method='linear'是如何处理你的论点的,⽽你给出的{}也不好,所以你应该只给出正确的输⼊(我认为这是我表述它们的⽅式是正确的),然后它就可以正常⼯作了。在
编辑:以txt格式读⼊数据,并编写以下代码。你能运⾏它看看这是否是你想要的结果吗?在import numpy as np
from scipy.interpolate import griddata
class d():
def __init__(self):
A0 = open("","rb") # i just copypasted your data into a txt (without first row), and reading it in in this class, so that the names are the same as yours
A1 = A0.readlines()
A = np.zeros((len(A1),3))
for i, l in enumerate(A1):
li = l.split()
A[i,0] = float(li[0])
A[i,1] = float(li[1])
A[i,2] = float(li[2])
self.Lon = A[:,0]
self.Lat = A[:,1]
self.Z = A[:,2]
data = d()
numcols, numrows = 30, 30
xi = np.linspace(data.Lon.min(), data.Lon.max(), numrows) yi = np.linspace(data.Lat.min(), data.Lat.max(), numcols) xi, yi = np.meshgrid(xi, yi)
x, y, z = data.Lon, data.Lat, data.Z
points = np.vstack((x,y)).T
values = z
wanted = (xi, yi)
zi = griddata(points, values, wanted)
import pylab as plt
fig = plt.figure(0, figsize=(8,4.5))
im = urf(xi, yi, zi)
fig2 = plt.figure(1, figsize=(8,4.5))
im = plt.scatter(xi, yi, c= zi)
plt.show()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。