開始使用免費開始

帶有標記與快顯視窗的 Folium 等值區域圖

現在你要在每個市議會選區的中心位置新增一個標記,顯示該選區的編號,以及該選區在 2017 年核發的建築許可數量。你在上一個練習建立的地圖可由 m 取得。

本練習屬於課程

在 Python 視覺化地理空間資料

檢視課程

練習說明

  • 找出每個市議會選區的幾何中心,並將其存到 districts_and_permits 這個 GeoDataFrame 的新欄位 center
  • 迭代 districts_and_permits,在每個選區的 center 加上一個標記。記得要把座標順序對調。
  • 在 for 迴圈中建立快顯視窗(popup),用來顯示選區編號與核發許可的數量。
  • 使用 .add_to() 把標記加到地圖上,並顯示地圖。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create center column for the centroid of each district
districts_and_permits['center'] = districts_and_permits.____.____

# Build markers and popups
for row in districts_and_permits.iterrows():
    row_values = row[1] 
    center_point = row_values[____]
    location = [center_point.____, center_point.____]
    popup = ('Council District: ' + str(row_values[____]) + 
             ';  ' + 'permits issued: ' + str(row_values[____]))
    marker = folium.Marker(location = location, popup = popup)
    marker.____(m)
    
# Display the map
display(m)
編輯並執行程式碼