開始使用免費開始

繪製納許維爾各社區地圖

這次你會將 GeoJSON 檔讀入 GeoDataFrame,快速查看納許維爾各社區的位置。

本練習屬於課程

在 Python 視覺化地理空間資料

檢視課程

練習說明

  • 以慣用別名匯入 geopandasmatplotlib.pyplot
  • 讀取社區的 GeoJSON 檔為名為 neighborhoods 的 GeoDataFrame,並用 .head() 列出前幾列。該檔案路徑已存於變數 neighborhoods_path
  • 繪製 neighborhoods,以 GeoDataFrame 的 name 欄位為多邊形著色,並使用 Dark2 色彩映射。這次不要加入圖例。
  • 顯示圖表。

動手互動練習

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

import geopandas as _____
import matplotlib.pyplot as _____

# Read in the neighborhoods geojson file
neighborhoods = gpd._____(neighborhoods_path)

# Print the first few rows of neighborhoods
print(neighborhoods.____())

# Plot the neighborhoods, color according to name and use the Dark2 colormap
neighborhoods.plot(_____ = 'name', _____ = 'Dark2')

# Show the plot.
plt.show()
編輯並執行程式碼