绘制纳什维尔社区地图
这一次,您将把一个 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()