MetPy PlotGeometry 可以用于向等高线图添加 Shapely LineString 吗?

问题描述 投票:0回答:1

metpy.plots.PlotGeometry 的参考指南指出,几何属性是要绘制的 Shapely 对象的集合。不幸的是,我无法让它发挥作用。

这是我尝试过的代码的缩减。

import metpy
from metpy.plots.declarative import PlotGeometry
import cartopy.crs as ccrs
from shapely.geometry import LineString

# Set projection and create line
proj = ccrs.PlateCarree()
geodL = proj.get_geod()
gLine = geodL.inv_intermediate(-95.383056, 29.762778, -81.669722, 41.482222, 20, return_back_azimuth=True)

# create the Shapely LineString and start assembling a MetPy plot
lineShape = LineString(list(zip(gLine.lons, gLine.lats)))
linePlt = PlotGeometry()
linePlt.geometry = lineShape # This fails with traitlets.traitlets.TraitError: The 'geometry' trait of a PlotGeometry instance expected an Iterable, not the LineString <LINESTRING (...

我觉得我错过了一些明显的东西。

python matplotlib shapely metpy
1个回答
0
投票

错误消息指出几何图形应该是一个集合,所以我想用

linePlt.geometry = lineShape
替换
linePlt.geometry = [lineShape]
应该有帮助?

© www.soinside.com 2019 - 2024. All rights reserved.