我有一个由许多单元格组成的模型网格,我想在matplotlib
basemap
.
使用,我首先投影点,然后使用'类pyproj
创建多边形以从中提取网格的外部坐标。然后我将它们恢复为 WGS84 以传递给我的绘图函数:shapely.geometry
Polygon
grid_x_mesh, grid_y_mesh = pyproj.transform(wgs84, nplaea, grid_lons, grid_lats)
grid_x = grid_x_mesh.ravel()
grid_y = grid_y_mesh.ravel()
grid_poly = Polygon(zip(grid_x, grid_y))
grid_x, grid_y = grid_poly.exterior.coords.xy
grid_plons, grid_plats = pyproj.transform(nplaea, wgs84, grid_x, grid_y)
然后,使用该matplotlib.basemap
方法,我将 WSG84 坐标投影到地图投影(本例中为 nplaea)和
grid_poly_x, grid_poly_y = m(grid_plons, grid_plats)
grid_poly_xy = zip(grid_poly_x, grid_poly_y)
grid_poly = Polygon(grid_poly_xy, facecolor='red', alpha=0.4)
plt.gca().add_patch(grid_poly)
尝试这样做时,我得到了一个纵横交错的图案,我认为它必须对我提供给多边形函数的坐标进行排序。
我认为这与我如何提取外部坐标有关,或者只是在创建要绘制的最终多边形时坐标列表的排序有关。
如果这是问题,是否有一种巧妙的方法可以正确订购这些?
绘制的多边形
特写