我想繪製一個輪廓不均勻間隔的數據在python中使用numpy,matplotlib plyplot和scipy。python numpy scipy griddata是南或所有相同的值
鑑於以下代碼片段,爲什麼zi要麼是空的,要麼是所有相同的值?
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
lon_min = 1.8783669
lon_max = 1.8792678
lat_min = 57.45827
lat_max = 57.459293
x = [ 520.99012099,652.23665224,800.,0.,520.99012099
652.23665224,800.,0.,520.99012099,652.23665224 ...]
y = [ 0.,379.47214076,437.53665689,600.,0.
379.47214076,437.53665689,600.,0.,379.47214076 ...]
z = [ 56.6,56.6,56.6,56.6,45.3,45.3,45.3,45.3,57.8,57.8 ...]
xi = np.linspace(lon_min,lon_max,10)
yi = np.linspace(lat_min,lat_max,10)
zi = griddata((x, y), z, (xi[None,:], yi[:,None]), method='nearest')
plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') # this is blank or all the same colour because zi is either nan or all the same number depending on the method I use.
應用一個比特調試它看起來像滋要麼是NAN如果我使用方法=立方/線性或全部相同數目如果我使用方法=最近
print xi
print yi
print zi
給出: XI = [1.8783669 1.878376 1.8783851 1.8783942 1.8784033 1.8784124 1.8784215 1.8784306 1.8784397 1.8784488 1.8784579 1.878467 1.8784761 1.8784852 1.8784943 1.8785034 1.8785125 ....]
yi = [57.45827 57.45828033 57.45829067 57.458301 57.45831133
57.45832167 57.458332 57.45834233 57.45835267 57.458363
57.45837333 57.45838367 57.458394 57.45840433 57.45841467
57.458425 57.45843533 57.45844567 57.458456 57.45846633 .... ]
zi = [[ nan nan nan ..., nan nan nan]
[ nan nan nan ..., nan nan nan]
[ nan nan nan ..., nan nan nan]
...,
[ nan nan nan ..., nan nan nan]
[ nan nan nan ..., nan nan nan]
[ nan nan nan ..., nan nan nan]]
zi = [[ 46.7 46.7 46.7 ..., 46.7 46.7 46.7]
[ 46.7 46.7 46.7 ..., 46.7 46.7 46.7]
[ 46.7 46.7 46.7 ..., 46.7 46.7 46.7]
...,
[ 46.7 46.7 46.7 ..., 46.7 46.7 46.7]
[ 46.7 46.7 46.7 ..., 46.7 46.7 46.7]
[ 46.7 46.7 46.7 ..., 46.7 46.7 46.7]]
你可以把它變成實際的Python代碼?處理幾乎不可運行的代碼是令人難以置信的煩惱。看到[這](http://stackoverflow.com/questions/16423774/string-representation-of-a-numpy-array-with-commas-separating-its-elements)一些幫助正確地輸出陣列。人們將更有可能以這種方式回答這個問題。 – YXD
griddata調用對於'scipy.interpolate.griddata'也是無效的 –
從文檔看起來好像你正在傳遞griddata正確的值 http://docs.scipy.org/doc/scipy/reference/generated/ scipy.interpolate.griddata.html 的GridData(點值,十一,方法=「線性」,fill_value =楠) 你逝去的5個值的GridData,你知道哪些值你以爲你是路過 – user1938107