我已经附上了我与x1c 0d1x工作的Map。我希望将蓝色线右侧的大部分中的值(在我提供的第二个图像中标记为
)从int更改为NaN。有没有一种方法可以选择一个特定的纬度/经度坐标和NaN周围的所有值?或者有没有其他更有效的方法?一位同事推荐了一个灵活的屏障来阻挡Map的这一部分,但我不确定如何进行编码。
我的Map是如何制作的:
fig = plt.figure(figsize=(10,10)) ax = fig.add_subplot(111,projection=rot) plot_cartopy(ax,lon,lat) plt.title("Month = May")
# set up the cartopy map
plt.contourf(lon,
lat,
new[4,:,:],
transform=ccrs.PlateCarree(), # tell matplotlib this is a map
cmap=cmocean.cm.thermal, # colormap
zorder=4 # zorder needs to be set so that it knows to plot it on top of the cartopy map ) plt.clim(0,100) plt.colorbar()
其中“new”是一个三维数组,维度为[month,x-coordinates,y-coordinates]。
谢谢你,谢谢!
1条答案
按热度按时间qlfbtfca1#
下面的代码给出了一些如何使用numpy.where函数将值更改为NaN的示例。
由于我没有你的数据,也不知道你的Map范围或线函数,我随机生成我的数据和线。我还生成了一个范围,可以更好地再现Map范围,但代码应该对您拥有的任何Map范围都有效。为了让您更好地理解,这里提供了全局Map和子集范围的打印示例。
在最后一个示例中,我将自定义行右侧的值更改为NaN。
结果可能看起来不精确的原因(例如NaN值与绘图中的自定义线不一致)是因为matplotlib contourf插值。由于matplotlib不会在任何值为NaN的情况下进行插值,因此任何接近NaN的点都将导致该空间无法进行可视化插值。在最后一个图中,我添加了一个NaN点的散点图,以向您显示它们正是自定义线右侧的点。
如果有帮助的话告诉我。