[ SKILL_DOCUMENTATION ]
# 地图与可视化
GeoPandas 通过集成 matplotlib 提供绘图功能。
## 基础绘图
python
# 简单绘图
gdf.plot()
# 自定义图形大小
gdf.plot(figsize=(10, 10))
# 设置颜色
gdf.plot(color='blue', edgecolor='black')
# 控制线宽
gdf.plot(edgecolor='black', linewidth=0.5)
## 等值区域图 (Choropleth Maps)
根据数据值对要素进行着色:
python
# 基础等值区域图
gdf.plot(column='population', legend=True)
# 指定颜色映射
gdf.plot(column='population', cmap='OrRd', legend=True)
# 其他颜色映射: 'viridis', 'plasma', 'inferno', 'YlOrRd', 'Blues', 'Greens'
### 分类方案
需要:`uv pip install mapclassify`
python
# 分位数
gdf.plot(column='population', scheme='quantiles', k=5, legend=True)
# 等间距
gdf.plot(column='population', scheme='equal_interval', k=5, legend=True)
# 自然断点 (Fisher-Jenks)
gdf.plot(column='population', scheme='fisher_jenks', k=5, legend=True)
# 其他方案: 'box_plot', 'headtail_breaks', 'max_breaks', 'std_mean'
# 传递参数给分类
gdf.plot(column='population', scheme='quantiles', k=7,
classification_kwds={'pct': [10, 20, 30, 40, 50, 60, 70, 80, 90]})
### 图例自定义
python
# 将图例放置在绘图外部
gdf.plot(column='population', legend=True,
legend_kwds={'loc': 'upper left', 'bbox_to_anchor': (1, 1)})
# 水平图例
gdf.plot(column='population', legend=True,
legend_kwds={'orientation': 'horizontal'})
# 自定义图例标签
gdf.plot(column='population', legend=True,
legend_kwds={'label': 'Population Count'})
# 为颜色条使用单独的轴
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(10, 6))
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.1)
gdf.plot(column='population', ax=ax, legend=True, cax=cax)
## 处理缺失数据
python
# 设置缺失值样式
gdf.plot(column='population',
missing_kwds={'color': 'lightgrey', 'edgecolor': 'red', 'hatch': '///',
'label': 'Missing data'})
## 多图层地图
组合多个 GeoDataFrame:
python
import matplotlib.pyplot as plt
# 创建基础绘图
fig, ax = plt.subplots(figsize=(10, 10))
# 添加图层
gdf1.plot(ax=ax, color='lightblue', edgecolor='black')
gdf2.plot(ax=ax, color='red', markersize=5)
gdf3.plot(ax=ax, color='green', alpha=0.5)
plt.show()
# 使用 zorder 控制图层顺序 (值越大越靠上)
gdf1.pl