開始使用免費開始

繪製 shapefile 多邊形

下一步是顯示多邊形地圖。 我們已經將 matplotlib.pyplot 載入為 pltgeopandas 載入為 gpd,而代表服務分區的 GeoDataFrame service_district 也已為你預先載入。

本練習屬於課程

在 Python 視覺化地理空間資料

檢視課程

練習說明

  • 先在 GeoDataFrame 上呼叫 .plot(),不帶其他參數,繪製服務分區。
  • plt.show() 檢視圖形。這一步已替你完成。
  • 接著再次使用 .plot() 方法,但這次加入 column='name' 依名稱為形狀上色,並加入 legend=True 以顯示這些名稱。記得顯示圖形。

動手互動練習

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

# Import packages
import geopandas as gpd
import matplotlib.pyplot as plt

# Plot the Service Districts without any additional arguments
service_district.____()
plt.show()

# Plot the Service Districts, color them according to name, and show a legend
service_district.plot(____ = 'name', ____ = True)
plt.____()
編輯並執行程式碼