繪製納許維爾各社區地圖
這次你會將 GeoJSON 檔讀入 GeoDataFrame,快速查看納許維爾各社區的位置。
本練習屬於課程
在 Python 視覺化地理空間資料
練習說明
- 以慣用別名匯入
geopandas與matplotlib.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()