我要一張顯示斯德哥爾摩市鎮的地圖。顯示如下。

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 中做到這一點?

uj5u.com熱心網友回復:
- 問題不包括幾何,所以有來源
- 這是繪制作為東部邊緣的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)

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/386434.html
標籤:Python matplotlib 几何学 大熊猫
下一篇:如何繪制聚類中心?
