Skip to main content

A python package to draw china maps more easily

Project description

cnmaps

Pytest Pypi publish Anaconda Conda downloads PyPI version Pypi Downloads Documentation Status contributions welcome style

cnmaps是一个可以让中国地图画起来更丝滑的地图类python扩展包

安装

安装cnmaps建议使用Python的解释器在3.8版本及以上。

使用conda安装

cnmaps最简单的安装方法是使用conda安装: $ conda install -c conda-forge cnmaps

使用pip安装

若要使用pip安装,则需要手动安装一些依赖:

  • cartopy: $ conda install -c conda-forge "cartopy>=0.20.0"
  • fiona: $ conda install -c conda-forge "fiona>=1.8.21"

在完成上述依赖的安装以后,你可以使用pip来安装cnmaps: $ pip install -U 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()

country-level

绘制省界

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()

province-level

绘制市界

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()

city-level

绘制区县界

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()

district-level

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')

logo-base

使用指南

针对本项目更多的使用方法,我们还有一份更详细的文档:cnmaps使用指南

引用

本项目适用的地图边界的数据源包括:

  1. GaryBikini/ChinaAdminDivisonSHP: v2.0, 2021, DOI: 10.5281/zenodo.4167299

海拔高度地形数据来自ASTER数字高程模型,并对原始数据进行了稀释。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cnmaps-1.1.4.tar.gz (50.6 MB view details)

Uploaded Source

Built Distribution

cnmaps-1.1.4-py3-none-any.whl (52.0 MB view details)

Uploaded Python 3

File details

Details for the file cnmaps-1.1.4.tar.gz.

File metadata

  • Download URL: cnmaps-1.1.4.tar.gz
  • Upload date:
  • Size: 50.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for cnmaps-1.1.4.tar.gz
Algorithm Hash digest
SHA256 f75997dd71071b351bfaa0f3e69bc810b4217f42c4676faf0ba7a2d1a87328a0
MD5 8e1c454dbda7790c8c9d057c7072baa8
BLAKE2b-256 2342f452089066cbd44e640af9883db81067a5efa0d70406b8e3c1d6008d6b5c

See more details on using hashes here.

File details

Details for the file cnmaps-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: cnmaps-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 52.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for cnmaps-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ac881f969f020fbde6e3a806981836444986f399ca87c1e5f38f32707fbe7f1a
MD5 613024464d1d7a5cd55bfc81d4aa1340
BLAKE2b-256 96a5b2522f26c3f2867dcb5c163ed6bef2a1bc37c09e8667615fb9518af72085

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page