1
背景地图一般用于绘制目的区域的地图背景。
由于我并不是一个专业的GIS工作者,日常对map的要求不高,因此地图系列我只做一些简单的尝试和分享。
由于地图相关的python库依赖较大,建议通过anaconda的conda-forge通道安装。如果当前环境中的库较多,则会长时间处于环境检查(solving environment)而无法安装成功,因此建议创建一个地图相关的虚环境。具体可参考我以前分享的Anaconda虚环境管理
基于geopandas和geoplot
建议使用anaconda的conda-forge通道安装:conda install -c conda-forge geopandas 建议使用anaconda的conda-forge通道安装:conda install -c conda-forge geoplot
import geopandas as gpd
import geoplot
import geoplot.crs as gcrs
# 导入数据
data = gpd.read_file("https://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/france.geojson")
geoplot.polyplot(data, projection=gcrs.AlbersEqualArea(), edgecolor='darkgrey', facecolor='lightgrey', linewidth=.3,
figsize=(12, 8))
2
基于cartopy
basemap已经停止维护,cartopy是很好的替代且具有更多维护:pip install cartopy
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure(figsize=(4, 4), dpi=200)
proj = ccrs.PlateCarree()
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
3
以上基于geopandas获取地图数据,并利用geoplot、cartopy快速绘背景地图。
共勉~