python 绘制 robin 投影下的世界地图

0、import

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

 

1、世界地图

plt.figure(figsize=(20, 15),
           facecolor='lightyellow'
          )
ax = plt.gca()

mymap = Basemap(projection='robin', 
                lat_0=50, lon_0=90,
                resolution='i',           
                area_thresh=5000.0
               )

# 绘制地图边界,填充海洋
mymap.drawmapboundary(fill_color='skyblue')
# 填充大陆和湖泊
mymap.fillcontinents(color='white',
                     lake_color='lightskyblue'
                    )

# 经线
mymap.drawmeridians(np.arange(0, 360, 60),
                    labels=[1,0,0,1]
                   )
# 纬线
mymap.drawparallels(np.arange(-90, 90.001, 30), 
                    labels=[1,0,0,1]
                   )

plt.show()

地图:

 

 2、填充中国各省、显示北京

plt.figure(figsize=(20, 15),
           facecolor='lightyellow'
          )
ax = plt.gca()

mymap = Basemap(projection='robin', 
                lat_0=50, lon_0=90,
                resolution='i',           
                area_thresh=5000.0
               )

# 绘制地图边界,填充海洋
mymap.drawmapboundary(fill_color='skyblue')
# 填充大陆和湖泊
mymap.fillcontinents(color='white',
                     lake_color='lightskyblue'
                    )

# 经线
mymap.drawmeridians(np.arange(0, 360, 60),
                    labels=[1,0,0,1]
                   )
# 纬线
mymap.drawparallels(np.arange(-90, 90.001, 30), 
                    labels=[1,0,0,1]
                   )

# 中国大陆
mymap.readshapefile(shapefile='gadm36_CHN_shp/gadm36_CHN_1',
                    name='states',
                    drawbounds=True
                   )
# 台湾
mymap.readshapefile('gadm36_TWN_shp/gadm36_TWN_0',
                    'taiwan',
                    drawbounds=True
                   )


# 在大陆各省形状上填充颜色
for shp_infos in [mymap.states, mymap.taiwan]:
    for shp in shp_infos:
    
        poly = Polygon(xy=shp,
                       facecolor='olivedrab',    # 填充草绿色
                      )
        ax.add_patch(poly)    # 在坐标系中添加省域多边形

# 用红色填充北京市
for info, shp in zip(mymap.states_info, mymap.states):
    proid = info['NAME_1']  # NAME_1 代表各省的名称
    if proid == 'Beijing':
        poly = Polygon(shp,
                       facecolor='r',
                       lw=3)
        ax.add_patch(poly)

# 显示地图
plt.show()

地图:

 

posted @ 2020-06-10 22:40  赏尔  阅读(1357)  评论(1编辑  收藏  举报