import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from mpl_toolkits.basemap import Basemap

1、有国界线和海岸线的黑白风地图

fig = plt.figure(figsize=(12, 8),    # 画布尺寸
                 facecolor='cornsilk'    # 画布背景色
# 绘制地图
m = Basemap(projection='lcc',    # 投影类型
            llcrnrlon=77, llcrnrlat=14,    # 左下角经纬的
            urcrnrlon=148, urcrnrlat=57,    # 右上角经纬度
            lat_1=33, lat_2=45, lon_0=100    # 
m.drawcoastlines()    # 海岸线
m.drawcountries()    # 国界线
plt.show()

2、添加省界线

fig = plt.figure(figsize=(12, 8),    # 画布尺寸
                 facecolor='cornsilk'    # 画布背景色
ax = plt.gca()   # 获取当前绘图区的坐标系
# 绘制地图
m = Basemap(projection='lcc',    # 投影类型
            llcrnrlon=77, llcrnrlat=14,    # 左下角经纬的
            urcrnrlon=148, urcrnrlat=57,    # 右上角经纬度
            lat_1=33, lat_2=45, lon_0=100    # 
m.drawcoastlines()    # 海岸线
m.drawcountries()    # 国界线
# 获取大陆各省的信息
m.readshapefile(shapefile='gadm36_CHN_shp/gadm36_CHN_1',
                name='states',
                drawbounds=True)   
plt.show()

3、在各省形状上填充颜色

fig = plt.figure(figsize=(12, 8),    # 画布尺寸
                 facecolor='cornsilk'    # 画布背景色
ax = plt.gca()   # 获取当前绘图区的坐标系
# 绘制地图
m = Basemap(projection='lcc',    # 投影类型
            llcrnrlon=77, llcrnrlat=14,    # 左下角经纬的
            urcrnrlon=148, urcrnrlat=57,    # 右上角经纬度
            lat_1=33, lat_2=45, lon_0=100    # 
m.drawcoastlines()    # 海岸线
m.drawcountries()    # 国界线
# 获取大陆各省的信息
m.readshapefile(shapefile='gadm36_CHN_shp/gadm36_CHN_1',
                name='states',
                drawbounds=True)
# 在大陆各省形状上填充颜色
for shp in m.states:
    poly = Polygon(xy=shp,
                   facecolor='olivedrab',    # 填充草绿色
    ax.add_patch(poly)    # 在坐标系中添加省域多边形
plt.show()

4、为台湾省填充颜色

fig = plt.figure(figsize=(12, 8),    # 画布尺寸
                 facecolor='cornsilk'    # 画布背景色
ax = plt.gca()   # 获取当前绘图区的坐标系
# 绘制地图
m = Basemap(projection='lcc',    # 投影类型
            llcrnrlon=77, llcrnrlat=14,    # 左下角经纬的
            urcrnrlon=148, urcrnrlat=57,    # 右上角经纬度
            lat_1=33, lat_2=45, lon_0=100    # 
m.drawcoastlines()    # 海岸线
m.drawcountries()    # 国界线
# 获取大陆各省的信息
m.readshapefile(shapefile='gadm36_CHN_shp/gadm36_CHN_1',
                name='states',
                drawbounds=True)
# 获取台湾省的 shp 信息
m.readshapefile('gadm36_TWN_shp/gadm36_TWN_0',
                'taiwan',
                drawbounds=True)
# 在大陆各省形状上填充颜色
for shp in m.states:
    poly = Polygon(xy=shp,
                   facecolor='olivedrab',    # 填充草绿色
    ax.add_patch(poly)    # 在坐标系中添加省域多边形
# 在台湾形状上填充颜色
for shp in m.taiwan:
    poly = Polygon(shp,
                   facecolor='olivedrab')
    ax.add_patch(poly)
plt.show()

5、用红色填充北京市

fig = plt.figure(figsize=(12, 8),    # 画布尺寸
                 facecolor='cornsilk'    # 画布背景色
ax = plt.gca()   # 获取当前绘图区的坐标系
# 绘制地图
m = Basemap(projection='lcc',    # 投影类型
            llcrnrlon=77, llcrnrlat=14,    # 左下角经纬的
            urcrnrlon=148, urcrnrlat=57,    # 右上角经纬度
            lat_1=33, lat_2=45, lon_0=100    # 
m.drawcoastlines()    # 海岸线
m.drawcountries()    # 国界线
# 获取大陆各省的信息
m.readshapefile(shapefile='gadm36_CHN_shp/gadm36_CHN_1',
                name='states',
                drawbounds=True)
# 获取台湾省的 shp 信息
m.readshapefile('gadm36_TWN_shp/gadm36_TWN_0',
                'taiwan',
                drawbounds=True)
# 在大陆各省形状上填充颜色
for shp in m.states:
    poly = Polygon(xy=shp,
                   facecolor='olivedrab',    # 填充草绿色
    ax.add_patch(poly)    # 在坐标系中添加省域多边形
# 在台湾形状上填充颜色
for shp in m.taiwan:
    poly = Polygon(shp,
                   facecolor='olivedrab')
    ax.add_patch(poly)
# 用红色填充北京市
for info, shp in zip(m.states_info, m.states):
    proid = info['NAME_1']  # NAME_1 代表各省的名称
    if proid == 'Beijing':
        poly = Polygon(shp,
                       facecolor='r',
                       lw=3)
        ax.add_patch(poly)
plt.show()

绘制指定国家行政区的地图需要下载 shapfile 文件, 可参看

https://baijiahao.baidu.com/s?id=1593631060848375411&wfr=spider&for=pc

https://blog.csdn.net/maoye/article/details/90157850