|
思路:中国地图画两遍,截取响相应经纬度范围的区域难点:中国海岸线以及南海岛屿等数据的准确性解决思路:在阿里云上获取中国地图的json文件,离线转成shp文件(网上有教程,也可留言获取)效果图:importmatplotlib.pyplotaspltimportcartopy.crsasccrsfromcartopy.ioimportshapereaderimportcartopy.featureascfeature#新建图层fig=plt.figure(figsize=(15,15))ax=fig.add_subplot(111,projection=ccrs.PlateCarree())#绘制中国地图shp_path=r'D:\ERA5\shp\中国\中国.shp'reader=shapereader.Reader(shp_path)forrecordinreader.records():ax.add_geometries([record.geometry],ccrs.PlateCarree(),facecolor='none')ax.add_feature(cfeature.RIVERS.with_scale('50m'))#添加河流,湖泊ax.add_feature(cfeature.LAKES.with_scale('50m'))ax.set_extent([73,135,13,55])#绘制南海子图sub_ax=fig.add_axes([0.764,0.22,0.15,0.15],projection=ccrs.PlateCarree())forrecordinreader.records():sub_ax.add_geometries([record.geometry],ccrs.PlateCarree(),facecolor='none')sub_ax.set_extent([105,125,0,25],crs=ccrs.PlateCarree())plt.show()
|
|