- 积分
- 5523
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2020-12-28
- 最后登录
- 1970-1-1
|
发表于 2023-2-18 14:18:49
|
显示全部楼层
可以通过plot()或者matploblib.pathes.Rectangle()来绘制,提供需要框定的区域进行绘制即可。
方法1:
- import numpy as np
- import cartopy.crs as ccrs
- import matplotlib.pyplot as plt
- fig = plt.figure(figsize=(8, 8),dpi=200)
- ax = plt.axes(projection=ccrs.NorthPolarStereo())
- # 绘制整个地图的边界
- ax.set_global()
- # # 构造框选区域的边界
- lon1, lon2, lat1, lat2 = 120, -20, -40, 40
- # 绘制红色线条框选出的区域
- ax.plot([lon1, lon2, lon2, lon1, lon1], [lat1, lat1, lat2, lat2, lat1],
- color='red', linewidth=2, transform=ccrs.PlateCarree())
- # 添加网格线和海岸线
- ax.gridlines(draw_labels=True)
- ax.coastlines()
- # 显示图形
- plt.show()
复制代码
方法2:
- import numpy as np
- import cartopy.crs as ccrs
- import matplotlib.pyplot as plt
- import matplotlib.patches as mpatches
- fig = plt.figure(figsize=(8, 8),dpi=200)
- ax = plt.axes(projection=ccrs.NorthPolarStereo())
- # 绘制整个地图的边界
- ax.set_global()
- lon1, lon2, lat1, lat2 = -120, -60, 0, 90
- # 绘制红色线条框选出的区域
- rect = mpatches.Rectangle((lon1, lat1), lon2 - lon1, lat2 - lat1,
- linewidth=2, edgecolor='red', facecolor='none',
- transform=ccrs.PlateCarree())
- ax.add_patch(rect)
- # 添加网格线和海岸线
- ax.gridlines(draw_labels=True)
- ax.coastlines()
- # 显示图形
- plt.show()
复制代码
|
-
-
|