簡體   English   中英

添加 label 或 geopandas plot 的位置

[英]Adding label or location for geopandas plot

我創建了一個地理熊貓 plot 的 state 及其所有管理位置。

map_df

NAME    ADMIN_LEVE  geometry    Party
0   Valsad  5   POLYGON ((73.02324 20.72237, 73.04599 20.70275...   3
1   Mumbai  None    POLYGON ((72.76066 18.83622, 72.75976 19.18686...   2
2   Mumbai  5   POLYGON ((72.83468 19.04853, 72.84073 19.04861...   2
3   Daman   5   POLYGON ((72.85930 20.47104, 72.86580 20.46770...   2
4   Bharathiya Kamala Nagar None    POLYGON ((72.87127 19.02556, 72.87158 19.02717...   5
... ... ... ... ...
79  Dantewada   5   POLYGON ((80.82621 19.34821, 80.83647 19.33215...   4
80  Raj Nandgaon    5   POLYGON ((80.81506 20.76028, 80.81328 20.74423...   1
81  Kanker  5   POLYGON ((80.91854 20.09037, 80.89668 20.09483...   2
82  Bastar  5   POLYGON ((80.92032 19.31699, 80.89713 19.31387...   1
83  Durg    5   POLYGON ((80.84896 20.66974, 80.82175 20.68357...   4

這是我用來創建 state 的 plot 的代碼:

fig, ax = plt.subplots(1, figsize=(200, 100))
cmap = colors.ListedColormap(['red', 'blue', 'green', 'yellow', 'orange'])
bounds = [1,2,3,4,5,6]
norm = colors.BoundaryNorm(bounds, cmap.N)
ax.axis('off')
map_df.plot(column='Party', cmap=cmap, norm=norm,linewidth=0.8, ax=ax, edgecolor='0.8')
plt.show()

當前 output:
電流輸出

所需的 output:將是整個 map 標記方式如下:
期望的輸出

我想更改此圖像,以便在該管理位置的 plot 內標記map_df['NAME']中的值。

任何幫助或建議將不勝感激。

您可以像這樣簡單地添加 label

ax = map_df.plot(column='Party', cmap=cmap, norm=norm,linewidth=0.8, ax=ax, edgecolor='0.8')
ax.annotate(label, xy=(x, y), xytext=(3, 3), textcoords="offset points")

其中label是您想要與定義的變量的 rest 一起添加的內容。 有關更多信息,請參閱此處

我還建議使用legends ,因為文本可能會在面積較小的區域溢出。 您可以在此處查看更多信息 - 在 Python 中自定義 Map 圖例和 Colors

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM