我有个问题,我可以在插值中掩盖海洋但不能掩盖湖泊。有人有办法吗?我把海洋的面具从:https://www.earthinversion.com/geophysics/plotting-the-geospatial-data-clipped-by-coastlines-in-python/#reading-data
到目前为止,我的代码是这样的
进口matplotlib。Pyplot as PLT import numpy as np from scipy.interpolate import griddata from mpl_toolkit。从matplotlib导入basemap。从matplotlib导入LinearSegmentedColormap。patch导入路径,PathPatch #数据坐标和值x =np. array([6.47, 4.8, 1.94, -4.57, 5.78, 3.95, 5.45, 0.38, 7.13, 12.43, 11.59, -1.083333333, -60.996, -83.144]) y =np. array([46.37, 43.9, 47.83, 48.36, 44.95, 43.57, 43.45, 43.12, 43.92, 51.35, 48.22, 52.88333333, 50.958, 37.02]) z =np. array([-29.5, -27.6, -32.5, -32.4, -16.0, -0.1, -12.3, -15.2, -36.2, -20.6,-38.2, -38.2, -2.0, -4.0])Arange (- 100,100,1, dtype='float64') yi =np。Arange (- 100,100,1, dtype='float64') xi, yi = np。meshgrid(xi, yi) # interpolate zi = griddata((x,y),z,(xi,yi),method='cubic') fig, ax= plt.subplots(figsize=(10,10)) m = Basemap(llcrnrlon=x.min()-0.1,llcrnrlat=y.min()-0.1,urcrnrlon=x.max()+0.1,urcrnrlat=y.max()+0.1,投影='merc',分辨率='h',area_thresh=1000.,ax=ax) m.c drawcoastlines() #在地图上绘制海岸线x,y=m(xi, yi) #转换坐标为地图比例尺cs=ax。等高线(x, y, zi, np。Linspace (- 40,0),extend='both',cmap='jet') #在地图上绘制数据。plt。Scatter (x, y) ##获取地图的限制:x0,x1 = ax.get_xlim() y0,y1 = ax.get_ylim() map_edges = np.array([[x0,y0],[x1,y0],[x1,y1],[x0,y1]]) ##获取所有用于绘制地图海岸线的多边形polyys = [p。##结合地图边缘多边形= [map_edges]+多边形[:]##创建一个路径补丁代码= [[Path. moveto]+[路径。LINETO for p in p[1:]] for p in polys] poly_lin = [v for p in polys for v in p] codes_lin = [xx for cs in code for xx in cs] path = path (poly_lin, codes_lin) patch = PathPatch(path, faceccolor ='white', lw=0) ax.add_patch(patch) plt.show()