# 使用Python绘制地图填充

## 一、准备工作

1.1 获取地图数据

```import geopandas as gpd

# 加载地图数据
```

1.2 安装绘图库

```!pip install matplotlib
!pip install mpl_toolkits.basemap
```

## 二、绘制基本地图

```import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

# 创建地图
fig = plt.figure(figsize=(10, 8))
m = Basemap(projection='merc', llcrnrlat=20, urcrnrlat=50,
llcrnrlon=70, urcrnrlon=140, resolution='h')

# 绘制海岸线和国家边界
m.drawcoastlines()
m.drawcountries()

# 绘制网格线
m.drawmeridians(range(0, 360, 30), labels=[0, 0, 0, 1])
m.drawparallels(range(10, 60, 10), labels=[1, 0, 0, 0])

# 显示地图
plt.show()
```

## 三、数据准备

```import pandas as pd

# 加载数据

# 合并地图数据和填充数据
merged = gdf.set_index('ID').join(data.set_index('ID'))

# 打印数据
```

## 四、地图填充

```# 绘制填充
fig = plt.figure(figsize=(10, 8))
m = Basemap(projection='merc', llcrnrlat=20, urcrnrlat=50,
llcrnrlon=70, urcrnrlon=140, resolution='h')

# 根据填充值填充地图
m.pcolor(m.x, m.y, merged['填充值'], cmap='Blues')

# 添加地理信息
m.drawcoastlines()
m.drawcountries()

# 显示颜色条
plt.colorbar(label='填充值')

# 显示地图
plt.show()
```

## 五、美化地图

5.1 添加标题和注释

```# 添加标题
plt.title('地图填充示例')

# 添加注释
plt.annotate('数据来源：xxx', xy=(0.05, 0.95),
xycoords='axes fraction', fontsize=10)
```

5.2 调整颜色和透明度

```# 调整填充颜色和透明度
m.pcolor(m.x, m.y, merged['填充值'], cmap='Blues', alpha=0.8)
```

5.3 添加图例

```# 添加图例
plt.legend()
```

## 六、保存地图

```# 保存为图片
fig.savefig('path/to/output.png', dpi=300)
```
{"ft_lang_label":"__label__zh","ft_lang_prob":0.6227488,"math_prob":0.92722267,"size":1766,"snap":"2023-40-2023-50","text_gpt3_token_len":993,"char_repetition_ratio":0.09194098,"word_repetition_ratio":0.11764706,"special_character_ratio":0.28595698,"punctuation_ratio":0.24012157,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9955639,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-03T00:41:32Z\",\"WARC-Record-ID\":\"<urn:uuid:af6714d8-a1c6-4ca4-816c-86fbaedbbcfe>\",\"Content-Length\":\"9167\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e923169a-25f7-491f-bb6d-205db0d3bd86>\",\"WARC-Concurrent-To\":\"<urn:uuid:709ede54-4173-4522-8979-f3ab7caa2d33>\",\"WARC-IP-Address\":\"42.193.219.182\",\"WARC-Target-URI\":\"https://www.enlanhao.com/code/308049.html\",\"WARC-Payload-Digest\":\"sha1:2N6AM3OXBMJSH5BCPPHMVXXTMFFWC3R5\",\"WARC-Block-Digest\":\"sha1:MHTOY5TVYUU3Y34YQUAI3KGTSPI3CEEN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100476.94_warc_CC-MAIN-20231202235258-20231203025258-00524.warc.gz\"}"}