在部分区域周围添加边框,matplotlib/geopandas
Add a border around parts of a region, matplotlib/geopandas
我要一张显示斯德哥尔摩市镇的地图。显示如下。
fig, ax = plt.subplots(1, figsize=(4, 4))
matplotlib.rcParams["figure.dpi"] = 250
ax.axis('off')
ax1 = geo_df1.plot(edgecolor='black', column=geo_df1.rel_grp, cmap=my_cmp, linewidth=0.3, ax=ax, categorical=True)#,
plt.show(ax1)
我想在东方添加一个放大的边界。像这样的东西。我如何在 matplotlib 中执行此操作?
- 问题不包括几何,所以有来源
- 这是绘制作为东边的 LineString 的简单案例。已经为示例目的生成了一个
import requests
import geopandas as gpd
import shapely.ops
import shapely.geometry
res = requests.get("http://data.insideairbnb.com/sweden/stockholms-län/stockholm/2021-10-29/visualisations/neighbourhoods.geojson")
# get geometry of stockholm
gdf = gpd.GeoDataFrame.from_features(res.json()).set_crs("epsg:4326")
# plot regions of stockholm
ax = gdf.plot()
# get linestring of exterior of all regions in stockhold
ls = shapely.geometry.LineString(shapely.ops.unary_union(gdf["geometry"]).exterior.coords)
b = ls.bounds
# clip boundary of stockholm to left edge
ls = ls.intersection(shapely.geometry.box(*[x-.2 if i==2 else x for i,x in enumerate(b)]))
# add left edge to plot
gpd.GeoSeries(ls).plot(edgecolor="yellow", lw=5, ax=ax)
我要一张显示斯德哥尔摩市镇的地图。显示如下。
fig, ax = plt.subplots(1, figsize=(4, 4))
matplotlib.rcParams["figure.dpi"] = 250
ax.axis('off')
ax1 = geo_df1.plot(edgecolor='black', column=geo_df1.rel_grp, cmap=my_cmp, linewidth=0.3, ax=ax, categorical=True)#,
plt.show(ax1)
我想在东方添加一个放大的边界。像这样的东西。我如何在 matplotlib 中执行此操作?
- 问题不包括几何,所以有来源
- 这是绘制作为东边的 LineString 的简单案例。已经为示例目的生成了一个
import requests
import geopandas as gpd
import shapely.ops
import shapely.geometry
res = requests.get("http://data.insideairbnb.com/sweden/stockholms-län/stockholm/2021-10-29/visualisations/neighbourhoods.geojson")
# get geometry of stockholm
gdf = gpd.GeoDataFrame.from_features(res.json()).set_crs("epsg:4326")
# plot regions of stockholm
ax = gdf.plot()
# get linestring of exterior of all regions in stockhold
ls = shapely.geometry.LineString(shapely.ops.unary_union(gdf["geometry"]).exterior.coords)
b = ls.bounds
# clip boundary of stockholm to left edge
ls = ls.intersection(shapely.geometry.box(*[x-.2 if i==2 else x for i,x in enumerate(b)]))
# add left edge to plot
gpd.GeoSeries(ls).plot(edgecolor="yellow", lw=5, ax=ax)