- 积分
- 41650
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-5-13
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 一大碗年糕 于 2025-9-20 16:20 编辑
想请教一下大家,Python画左图里绿色平行四边形的垂直剖面环流该用什么比较方便呀?😂metpy的cross section好像只能画任意两点之间的剖面2025.9.20更新,添加平行四边形
- from matplotlib.patches import Polygon as MplPolygon
- import numpy as np
- import math
- import cartopy.crs as ccrs
- def add_parallelogram(ax, center_lon, center_lat, width_deg, height_deg, skew_deg=0.3,
- angle_deg=0, edgecolor='blue', linewidth=2, linestyle='-',
- zorder=2, label=None):
- """
- 在 cartopy 地理坐标中添加一个平行四边形。
-
- 参数:
- - ax: cartopy axes
- - center_lon, center_lat: 中心经纬度
- - width_deg, height_deg: 平行四边形宽高(单位:度)
- - skew_deg: 水平方向的偏移量(控制平行四边形形状)
- - angle_deg: 绕中心顺时针旋转角度(度)
- - edgecolor, linewidth, linestyle: 样式
- """
- angle_rad = math.radians(angle_deg)
- dx, dy = width_deg / 2, height_deg / 2
- # 定义平行四边形的四个角
- corners = [(-dx, -dy), (dx, -dy), (dx + skew_deg, dy), (-dx + skew_deg, dy)]
-
- # 旋转 + 平移
- rotated_corners = []
- for x, y in corners:
- x_rot = x * math.cos(angle_rad) - y * math.sin(angle_rad) + center_lon
- y_rot = x * math.sin(angle_rad) + y * math.cos(angle_rad) + center_lat
- rotated_corners.append((x_rot, y_rot))
-
- # 绘制
- poly = MplPolygon(rotated_corners, closed=True, edgecolor=edgecolor,
- facecolor='none', linewidth=linewidth, linestyle=linestyle,
- transform=ccrs.PlateCarree(), zorder=zorder, label=label)
- ax.add_patch(poly)
- return poly
复制代码
|
-
|