Cnmaps
这是一个可以让中国地图画起来更丝滑的python扩展包
Install / Use
/learn @cnmetlab/CnmapsREADME
安装
安装 cnmaps 需要满足 Python 的解释器在 3.9 版本及以上。
使用pip安装
cnmaps 最简单也最快的安装方法是使用 pip 来安装 cnmaps: $ pip install -U cnmaps
使用conda安装
你也可以使用 conda 安装: $ conda install -c conda-forge cnmaps
快速开始
绘制国界
用最简单直接的方式,来绘制你的第一张中国地图。
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(level='国'))
plt.show()

绘制省界
cnmaps还可以绘制各省(特区/直辖市)的地图
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(level='省'), linewidth=0.8, color='r')
plt.show()

绘制市界
cnmaps可以绘制市级的行政区地图。
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(level='市'), linewidth=0.5, color='g')
plt.show()

绘制区县界
cnmaps可以绘制区县级的行政区地图。
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(level='区县'), linewidth=0.8, color='r')
plt.show()

Logo
本项目的Logo地图是如何绘制的?请执行下面的代码。
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps
fig = plt.figure(figsize=(5,5))
proj = ccrs.Orthographic(central_longitude=100.0, central_latitude=30)
ax = fig.add_subplot(111, projection=proj)
ax.stock_img()
china, sourth_sea = get_adm_maps(level='国', only_polygon=True)
ax.set_global()
ax.add_geometries(china, crs=ccrs.PlateCarree(), edgecolor='r', facecolor='r')
ax.add_geometries(sourth_sea, crs=ccrs.PlateCarree(), edgecolor='r')
ax.outline_patch.set_edgecolor('white')
plt.savefig('../static/images/logo-base.png', bbox_inches='tight')

使用指南
针对本项目更多的使用方法,我们还有一份更详细的文档:cnmaps使用指南
引用
本项目适用的地图边界的数据源包括:
- GaryBikini/ChinaAdminDivisonSHP: v2.0, 2021, DOI: 10.5281/zenodo.4167299
海拔高度地形数据来自ASTER数字高程模型,并对原始数据进行了稀释。
Related Skills
node-connect
338.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
83.6kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
83.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
338.7kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
