You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Python下绘制飓风路径的Basemap代码转换为Cartopy版本

转换后的Cartopy实现代码
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature

# 初始化米勒投影画布,匹配原Basemap的地理范围
fig = plt.figure(figsize=(10, 8))
proj = ccrs.Miller()
ax = fig.add_subplot(1, 1, 1, projection=proj)
# 设置地图边界:西经110°至西经90°,北纬22.5°至北纬38°
ax.set_extent([-110, -90, 22.5, 38], crs=ccrs.PlateCarree())

# 绘制飓风路径,无需提前转换坐标,通过transform指定经纬度坐标系即可
ax.plot(carlalon, carlalat, 'go-', label='Carla, 1961', transform=ccrs.PlateCarree())
ax.plot(beulahlon, beulahlat, 'bo-', label='Beulah, 1967', transform=ccrs.PlateCarree())
ax.plot(celialon, celialat, 'yo-', label='Celia, 1970', transform=ccrs.PlateCarree())
ax.plot(allenlon, allenlat, 'co-', label='Allen, 1980', transform=ccrs.PlateCarree())
ax.plot(alicialon, alicialat, 'mo-', label='Alicia, 1983', transform=ccrs.PlateCarree())
ax.plot(gilbertlon, gilbertlat, 'ko-', label='Gilbert, 1988', transform=ccrs.PlateCarree())
ax.plot(bretlon, bretlat, 'o-', color='#9DFF5E', label='Bret, 1999', transform=ccrs.PlateCarree())
ax.plot(ritalon, ritalat, 'o-', color='#F39C12', label='Rita, 2005', transform=ccrs.PlateCarree())
ax.plot(ikelon, ikelat, 'ro-', label='Ike, 2008', transform=ccrs.PlateCarree())
ax.plot(harveylonarray2, harveylatarray2, 'o-', color='#FF8CC2', label='Harvey, 2017', transform=ccrs.PlateCarree())

# 加载高分辨率地理要素,匹配原Basemap的resolution='h'参数
ax.add_feature(cfeature.COASTLINE.with_scale('10m'), linewidth=0.8)
ax.add_feature(cfeature.LAND.with_scale('10m'), facecolor='lightgray')
ax.add_feature(cfeature.STATES.with_scale('10m'), linewidth=0.5)
ax.add_feature(cfeature.BORDERS.with_scale('10m'), linewidth=0.6)

plt.title('Texas Hurricanes Paths, 1950-2017')
plt.legend(loc='upper left')
plt.show()
使用说明
  • 原代码中需要提前调用Basemap实例转换经纬度为坐标的步骤可以省略,Cartopy通过transform参数自动完成坐标系转换
  • 第一次运行时如果触发高分辨率地理要素下载,等待自动完成即可;若加载速度过慢,可将所有with_scale('10m')修改为with_scale('50m')使用中等分辨率数据
  • 可自行调整figsize、地理要素的linewidth、facecolor参数调整绘图样式匹配需求

内容的提问来源于stack exchange,提问作者jakehou97

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 23:54:00