现在我有一个24 * 20阵列如下:
In [748]: zb_mean
Out[748]:
array([[ nan, 20.68575654, 14.11937546, 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,
... ... ...
... ... ...
In [749]: zb_mean.shape
Out[749]: (24, 20)
然后我根据下面的纬度/经度创建一个网格:
xi = np.arange(-66,-72,-0.25)
yi = np.arange(40.5,45.5,0.25)
In [755]: len(xi),len(yi)
Out[755]: (24, 20)
xxb,yyb = np.meshgrid(xi, yi)
现在网格和数组有相同的维度,我想在每个小网格的中心用数组(zb_mean)的对应值绘制这个网格(xxb,yyb),我该怎么办?非常感谢你!
答案 0 :(得分:2)
如果我理解你的问题是正确的,你想要绘制具有有效值的单元格。诀窍是使用masked_invalid方法,它将使用numpy函数masked_invalid隐藏你的nan值。我创建了一个关于如何做到这一点的小例子:
import numpy as np
test=np.asarray([[10,15,20,50],[30,40,nan,70],[nan,10,nan,25],[100,50,nan,60]])
test=np.ma.masked_invalid(test)
xi = np.arange(-66,-70,-1)
yi = np.arange(40.5,44.5,1)
xxb,yyb = np.meshgrid(xi, yi)
c=pcolor(xxb,yyb,test)
colorbar(c)
希望这会有所帮助。干杯,特隆德