[英]Use two shapefiles in geopandas
我必須要shapefile。 一種是 POLYGON,代表瑞典的行政區。 另一個是代表國家湖泊的 POINTS。 我有與行政區相關的數據,想添加湖泊以使 map 更漂亮。
這是我創建沒有湖泊的 map 的腳本。
variable = 'förändring1'
vmin, vmax = -2, 4
fig, ax = plt.subplots(1, figsize=(10, 16))
matplotlib.rcParams["figure.dpi"] = 250
ax.axis('off')
ax.set_title('TITLE, REGIONS\n Q1 2020 - Q2 2021', fontdict={'fontsize': '24', 'fontweight' : '3', 'fontname':'Open Sans'})
ax.annotate('X', xy=(0.7, .05), xycoords='figure fraction', fontsize=11, color='#555555')
legend = plt.legend(title="title",
loc=4, fontsize='small', fancybox=True)
geo_df1.plot(edgecolor='black', column=variable, cmap=my_cmp, linewidth=0.3, ax=ax, categorical=True, legend=True,
legend_kwds=dict(loc='lower right',
title='Förändring\n%-enheter',
prop = {'size' : 15}))
我的地區 shapefile 如下所示:
LA-kod LA-namn geometry
0 LA1903 Eskilstuna POLYGON ((568494.857 6523152.063, 565723.456 6...
1 LA1925 Borås POLYGON ((396919.129 6351819.960, 395817.199 6...
2 LA1948 Sundsvall MULTIPOLYGON (((623003.025 6929654.815, 628496...
3 LA1960 Lycksele POLYGON ((704138.531 7189721.517, 695708.319 7...
4 LA1965 Pajala POLYGON ((888013.662 7448254.868, 868700.048 7...
... ... ... ...
64 LA1902 Nyköping-Oxelösund MULTIPOLYGON (((617964.321 6507990.893, 620313...
65 LA1944 Gävle POLYGON ((583931.306 6691340.733, 576700.277 6...
66 LA1949 Kramfors MULTIPOLYGON (((640892.553 6993927.028, 639395...
67 LA1934 Örebro POLYGON ((519879.892 6521506.409, 516154.724 6...
68 LA1921 Halmstad POLYGON ((373979.424 6248279.617, 374683.890 6...
69 rows × 3 columns
我的湖泊 shapefile 如下所示:
SJOID geometry
0 631121-147437 POINT (523392.000 6309304.000)
1 707350-149283 POINT (534314.000 7069077.000)
2 633919-152479 POINT (573459.000 6337866.000)
3 763280-176148 POINT (793878.000 7634014.000)
4 656371-143806 POINT (484086.000 6561244.000)
... ... ...
106595 753912-164311 POINT (676771.000 7538815.000)
106596 753912-165416 POINT (687817.000 7538959.000)
106597 753912-174751 POINT (781138.000 7540177.000)
106598 743421-188986 POINT (924825.000 7437141.000)
106599 753913-178160 POINT (815220.000 7540632.000)
106600 rows × 2 columns
你能試一下嗎
ax1=geo_df1.plot()
geo_df2.plot(ax=ax1)
其中,geo_df1 和 geo_df2 表示來自兩個 shapefile 的地理數據幀以及必要的參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.