![](https://img2024.cnblogs.com/blog/1987782/202411/1987782-20241130002507635-865022621.png)
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.path as mpath
def plot_polar_map(dmeridian: float = 30.0,
dparallel: float = 15.0):
"""
绘制北极区域的极区投影地图,并添加经纬度网格和标签。
参数:
dmeridian (float): 经度网格线的间隔(单位:度),默认为30.0
dparallel (float): 纬度网格线的间隔(单位:度),默认为15.0
"""
fig = plt.figure(figsize=[8, 8])
projection = ccrs.NorthPolarStereo()
ax = plt.axes(projection=projection)
ax.coastlines(linewidths=0.5)
ax.add_feature(cfeature.LAND, facecolor='lightgray')
ax.set_extent([0, 360, 0, 90], ccrs.PlateCarree())
num_merid = int(360.0 / dmeridian + 1.0)
num_parra = int(90.0 / dparallel + 1.0)
gl = ax.gridlines(crs=ccrs.PlateCarree(),
xlocs=np.linspace(0.0, 360.0, num_merid),
ylocs=np.linspace(0.0, 90.0, num_parra),
linestyle="--", linewidth=1, color='k', alpha=0.5)
theta = np.linspace(0, 2 * np.pi, 120)
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
center, radius = [0.5, 0.5], 0.5
circle = mpath.Path(verts * radius + center)
ax.set_boundary(circle, transform=ax.transAxes)
va = 'center'
ha = 'center'
degree_symbol = u'\u00B0'
lond = np.linspace(0, 360, num_merid)
latd = np.zeros(len(lond))
for alon, alat in zip(lond, latd):
projx1, projy1 = ax.projection.transform_point(alon, alat, ccrs.Geodetic())
if alon > 0 and alon < 180:
ha = 'left'
va = 'center'
if alon > 180 and alon < 360:
ha = 'right'
va = 'center'
if np.abs(alon - 180) < 0.01:
ha = 'center'
va = 'bottom'
if alon == 0.:
ha = 'center'
va = 'top'
if alon < 360.:
txt = f' {int(alon)} ' + degree_symbol
ax.text(projx1, projy1, txt, va=va, ha=ha, color='g')
lond2 = 315 * np.ones(len(lond))
latd2 = np.linspace(0, 90, num_parra)
va, ha = 'center', 'center'
for alon, alat in zip(lond2, latd2):
projx1, projy1 = ax.projection.transform_point(alon, alat, ccrs.Geodetic())
txt = f' {int(alat)} ' + degree_symbol
ax.text(projx1, projy1, txt, va=va, ha=ha, color='r')
fig.canvas.manager.set_window_title('北极区域极区投影地图')
plt.show()
plot_polar_map(dmeridian=30.0, dparallel=15.0)
查看绘制南极代码
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.path as mpath
def plot_south_polar_map(dmeridian: float = 30.0,
dparallel: float = 15.0):
"""
绘制南极区域的极区投影地图,并添加经纬度网格和标签。
参数:
dmeridian (float): 经度网格线的间隔(单位:度),默认为30.0
dparallel (float): 纬度网格线的间隔(单位:度),默认为15.0
"""
fig = plt.figure(figsize=[8, 8])
projection = ccrs.SouthPolarStereo()
ax = plt.axes(projection=projection)
ax.coastlines(linewidths=0.5)
ax.add_feature(cfeature.LAND, facecolor='lightgray')
ax.set_extent([0, 360, -90, 0], ccrs.PlateCarree())
num_merid = int(360.0 / dmeridian + 1.0)
num_parra = int(90.0 / dparallel + 1.0)
gl = ax.gridlines(crs=ccrs.PlateCarree(),
xlocs=np.linspace(0.0, 360.0, num_merid),
ylocs=np.linspace(-90.0, 0.0, num_parra),
linestyle="--", linewidth=1, color='k', alpha=0.5)
theta = np.linspace(0, 2 * np.pi, 120)
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
center, radius = [0.5, 0.5], 0.5
circle = mpath.Path(verts * radius + center)
ax.set_boundary(circle, transform=ax.transAxes)
va = 'center'
ha = 'center'
degree_symbol = u'\u00B0'
lond = np.linspace(0, 360, num_merid)
latd = np.zeros(len(lond))
for alon, alat in zip(lond, latd):
projx1, projy1 = ax.projection.transform_point(alon, alat, ccrs.Geodetic())
if alon > 0 and alon < 180:
ha = 'left'
va = 'center'
if alon > 180 and alon < 360:
ha = 'right'
va = 'center'
if np.abs(alon - 180) < 0.01:
ha = 'center'
va = 'bottom'
if alon == 0.:
ha = 'center'
va = 'top'
if alon < 360.:
txt = f' {int(alon)} ' + degree_symbol
ax.text(projx1, projy1, txt, va=va, ha=ha, color='g')
lond2 = 315 * np.ones(len(lond))
latd2 = np.linspace(-90, 0, num_parra)
va, ha = 'center', 'center'
for alon, alat in zip(lond2, latd2):
projx1, projy1 = ax.projection.transform_point(alon, alat, ccrs.Geodetic())
txt = f' {int(alat)} ' + degree_symbol
ax.text(projx1, projy1, txt, va=va, ha=ha, color='r')
fig.canvas.manager.set_window_title('南极区域极区投影地图')
plt.show()
plot_south_polar_map(dmeridian=30.0, dparallel=15.0)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
· 用 DeepSeek 给对象做个网站,她一定感动坏了
· .NET 8.0 + Linux 香橙派,实现高效的 IoT 数据采集与控制解决方案
· DeepSeek处理自有业务的案例:让AI给你写一份小众编辑器(EverEdit)的语法着色文件
2023-11-30 Vite 打包配置说明及插件使用
2023-11-30 Vue3 + Vite中使用unocss