goeopandas情节形状并应用不透明的外部形状
我正在绘制城市边界(geopandas 数据框),并使用 contextily 添加了底图。 我想对城市范围之外的地图区域应用不透明度。 下面的示例显示了与预期效果相反的效果,因为不透明度应该应用于除城市范围之外的任何地方。
import osmnx as ox
import geopandas as gpd
import contextily as cx
berlin = ox.geocode_to_gdf('Berlin,Germany')
fig, ax = plt.subplots(1, 1, figsize=(10,10))
_ = ax.axis('off')
berlin.plot(ax=ax,
color='white',
edgecolor='black',
alpha=.7,
)
# basemap
cx.add_basemap(ax,crs=berlin.crs,)
plt.savefig('stackoverflow_question.png',
dpi=100,
bbox_inches='tight',
)
I am plotting a city boundary (geopandas dataframe) to which I added a basemap using contextily.
I would like to apply opacity to the region of the map outside of the city limits.
The below example shows the opposite of the desired effect, as the opacity should be applied everywhere except whithin the city limits.
import osmnx as ox
import geopandas as gpd
import contextily as cx
berlin = ox.geocode_to_gdf('Berlin,Germany')
fig, ax = plt.subplots(1, 1, figsize=(10,10))
_ = ax.axis('off')
berlin.plot(ax=ax,
color='white',
edgecolor='black',
alpha=.7,
)
# basemap
cx.add_basemap(ax,crs=berlin.crs,)
plt.savefig('stackoverflow_question.png',
dpi=100,
bbox_inches='tight',
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个新的多边形,该多边形是几何形状总界限的缓冲区,减去几何
“ https://i.sstatic.net/rstpa.jpg” alt =“在此处输入图像说明”>
You can create a new polygon that is a buffer on the total bounds of your geometry minus your geometry