Python 在cartopy上绘制形状多边形

Python 在cartopy上绘制形状多边形,python,matplotlib,shapely,cartopy,Python,Matplotlib,Shapely,Cartopy,我想在卡通地图上画一个多边形。我看过Cartopy和shapely文档,也看过StackOverflow中的各种解决方案,但似乎什么都不起作用,我不知道为什么 以下是我所拥有的: 从shapely.geometry.polygon导入多边形 将cartopy.crs作为CCR导入 将cartopy.feature导入为cfeature 将matplotlib.pyplot作为plt导入 #绘制地图 界限=[(-122.,-72,25,50.)] plt.图(figsize=(5,3)) ax=p

我想在卡通地图上画一个多边形。我看过Cartopy和shapely文档,也看过StackOverflow中的各种解决方案,但似乎什么都不起作用,我不知道为什么

以下是我所拥有的:

从shapely.geometry.polygon导入多边形
将cartopy.crs作为CCR导入
将cartopy.feature导入为cfeature
将matplotlib.pyplot作为plt导入
#绘制地图
界限=[(-122.,-72,25,50.)]
plt.图(figsize=(5,3))
ax=plt.轴(投影=ccrs.LambertConformal())
ax.set_区段(*界限,crs=ccrs.PlateCarree())
最大添加要素(C要素。海岸线,比例('50m'),线宽=0.75)
ax.add_特征(cfeature.STATES,线宽=0.5)
#添加多边形
ax.add_几何体([polygon],crs=ccrs.PlateCarree(),facecolor='b',edgecolor='black',alpha=0.5)
使用当前代码,我只得到一张美国的空白图像。我认为: 1) 投影错误,而是将多边形放置在其他位置,或者2)多边形被正确放置在地图上,只是由于未正确设置
ax.add_geometry
属性而无法显示

对于上述内容,
多边形
如下所示:

polygon=多边形[(-6719446.1597775828747162.244957967),
(-6714522.73594268, 8747162.244957967),
(-6714522.73594268, 8742238.821123065),
(-6704675.888272878, 8742238.821123065),
(-6704675.888272878, 8737315.397288164),
(-6689905.616768174, 8737315.397288164),
(-6689905.616768174, 8732391.973453263),
(-6684982.1929332735, 8732391.973453263),
(-6684982.1929332735, 8727468.549618362),
(-6675135.345263471, 8727468.549618362),
(-6675135.345263471, 8722545.125783462),
(-6665288.497593668, 8722545.125783462),
(-6665288.497593668, 8717621.70194856),
(-6660365.073758768, 8717621.70194856),
(-6660365.073758768, 8712698.27811366),
(-6655441.649923867, 8712698.27811366),
(-6655441.649923867, 8717621.70194856),
(-6650518.226088965, 8717621.70194856),
(-6650518.226088965, 8707774.854278758),
(-6640671.378419163, 8707774.854278758),
(-6640671.378419163, 8702851.430443857),
(-6625901.106914459, 8702851.430443857),
(-6625901.106914459, 8693004.582774054),
(-6611130.835409755, 8693004.582774054),
(-6611130.835409755, 8688081.158939153),
(-6606207.411574854, 8688081.158939153),
(-6606207.411574854, 8678234.31126935),
(-6601283.987739952, 8678234.31126935),
(-6601283.987739952, 8673310.887434449),
(-6591437.140070151, 8673310.887434449),
(-6591437.140070151, 8663464.039764646),
(-6586513.716235249, 8663464.039764646),
(-6586513.716235249, 8653617.192094844),
(-6576666.868565448, 8653617.192094844),
(-6576666.868565448, 8648693.768259943),
(-6571743.444730546, 8648693.768259943),
(-6571743.444730546, 8638846.92059014),
(-6561896.597060744, 8638846.92059014),
(-6561896.597060744, 8633923.496755239),
(-6556973.173225842, 8633923.496755239),
(-6556973.173225842, 8624076.649085436),
(-6552049.749390941, 8624076.649085436),
(-6552049.749390941, 8619153.225250535),
(-6547126.32555604, 8619153.225250535),
(-6547126.32555604, 8614229.801415635),
(-6542202.9017211385, 8614229.801415635),
(-6542202.9017211385, 8609306.377580734),
(-6537279.477886237, 8609306.377580734),
(-6537279.477886237, 8599459.529910931),
(-6527432.630216435, 8599459.529910931),
(-6527432.630216435, 8589612.682241129),
(-6522509.206381533, 8589612.682241129),
(-6522509.206381533, 8584689.258406227),
(-6512662.358711731, 8584689.258406227),
(-6512662.358711731, 8574842.410736425),
(-6507738.93487683, 8574842.410736425),
(-6507738.93487683, 8569918.986901524),
(-6502815.511041929, 8569918.986901524),
(-6502815.511041929, 8564995.563066622),
(-6497892.087207028, 8564995.563066622),
(-6497892.087207028, 8560072.139231721),
(-6492968.663372126, 8560072.139231721),
(-6492968.663372126, 8550225.29156192),
(-6488045.239537226, 8550225.29156192),
(-6488045.239537226, 8545301.867727019),
(-6483121.815702325, 8545301.867727019),
(-6483121.815702325, 8540378.443892118),
(-6478198.391867423, 8540378.443892118),
(-6478198.391867423, 8535455.020057216),
(-6473274.968032522, 8535455.020057216),
(-6473274.968032522, 8525608.172387414),
(-6468351.544197621, 8525608.172387414),
(-6468351.544197621, 8520684.748552512),
(-6463428.1203627195, 8520684.748552512),
(-6463428.1203627195, 8510837.90088271),
(-6458504.696527818, 8510837.90088271),
(-6458504.696527818, 8500991.053212907),
(-6453581.272692917, 8500991.053212907),
(-6453581.272692917, 8496067.629378006),
(-6448657.848858016, 8496067.629378006),
(-6448657.848858016, 8486220.781708203),
(-6443734.425023114, 8486220.781708203),
(-6443734.425023114, 8476373.9340384),
(-6438811.001188213, 8476373.9340384),
(-6438811.001188213, 8471450.5102035),
(-6433887.577353312, 8471450.5102035),
(-6433887.577353312, 8461603.662533697),
(-6428964.15351841, 8461603.662533697),
(-6428964.15351841, 8451756.814863894),
(-6424040.72968351, 8451756.814863894),
(-6424040.72968351, 8446833.391028993),
(-6419117.305848609, 8446833.391028993),
(-6419117.305848609, 8436986.543359192),
(-6414193.882013707, 8436986.543359192),
(-6414193.882013707, 8427139.69568939),
(-6409270.458178806, 8427139.69568939),
(-6409270.458178806, 8422216.271854488),
(-6404347.034343905, 8422216.271854488),
(-6404347.034343905, 8412369.424184686),
(-6399423.610509004, 8412369.424184686),
(-6399423.610509004, 8402522.576514883),
(-6394500.186674103, 8402522.576514883),
(-6394500.186674103, 8392675.72884508),
(-6389576.762839202, 8392675.72884508),
(-6389576.762839202, 8387752.305010179),
(-6379729.915169399, 8387752.305010179),
(-6379729.915169399, 8377905.457340376),
(-6374806.491334498, 8377905.457340376),
(-6374806.491334498, 8372982.033505476),
(-6369883.067499597, 8372982.033505476),
(-6369883.067499597, 8363135.1858356735),
(-6364959.643664695, 8363135.1858356735),
(-6364959.643664695, 8343441.490496069),
(-63
from shapely.geometry.polygon import Polygon
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

# make the map
bounds = [-122., -72., 25., 50.]
plt.figure(figsize=(5, 3))
ax = plt.axes(projection=ccrs.LambertConformal())
ax.set_extent(bounds, crs=ccrs.PlateCarree())
ax.add_feature(cfeature.COASTLINE.with_scale('110m'), linewidth=0.75)
ax.add_feature(cfeature.STATES, linewidth=0.5)

# this makes use of 4 points within
# .. the range of the plotting areas
# x-range: ax.get_xlim()-->(-2649555.771560139, 2450710.00017399)
# y-range: ax.get_ylim()-->(-1558882.932595755, 1491858.0195908)
# to create a sample polygon, `pgon` for demonstration
xmin, xmax = ax.get_xlim()
ymin, ymax = ax.get_ylim()
xs, ys = xmax-xmin, ymax-ymin
padx, pady = xs/6.0, ys/6.0
xll, yll, xur, yur = xmin+padx, ymin+pady, xmax-padx, ymax-pady
# create a sample polygon, `pgon`
pgon = Polygon(((xll, yll),
        (xll, yur),
        (xur, yur),
        (xur, yll),
        (xll, yll)))

# this plots the polygon
# must declare correct coordinate system of the data
# here, coordinates in `pgon` are LambertConformal, 
# it must be specified here as `crs=ccrs.LambertConformal()`
ax.add_geometries([pgon], crs=ccrs.LambertConformal(), facecolor='b', edgecolor='red', alpha=0.8)

plt.show()