แผนที่ย่านใน Nashville
คราวนี้จะอ่านไฟล์ GeoJSON เข้าสู่ GeoDataFrame เพื่อดูภาพรวมว่าย่านต่างๆ ใน Nashville ตั้งอยู่ที่ไหน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การแสดงผลข้อมูลเชิงภูมิศาสตร์ด้วย Python
คำแนะนำการฝึกหัด
- Import
geopandasและmatplotlib.pyplotโดยใช้ alias ตามธรรมเนียม - อ่านไฟล์ GeoJSON ของย่านต่างๆ เข้าสู่ GeoDataFrame ชื่อ
neighborhoodsแล้วแสดงแถวแรกๆ ด้วย.head()โดย path ของไฟล์นี้เก็บไว้ในตัวแปรชื่อneighborhoods_path - พล็อต
neighborhoodsโดยระบายสีรูปหลายเหลี่ยมตามคอลัมน์nameของ GeoDataFrame และใช้ color mapDark2คราวนี้ไม่ต้องแสดง legend - แสดงกราฟ
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
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()