world map without rivers with matplotlib / Basemap?

后端 未结 7 768
生来不讨喜
生来不讨喜 2021-01-31 10:37

Would there be a way to plot the borders of the continents with Basemap (or without Basemap, if there is some other way), without those annoying rivers coming along? Especially

7条回答
  •  误落风尘
    2021-01-31 11:00

    As per my comment to @sampo-smolander

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    
    fig = plt.figure(figsize=(8, 4.5))
    plt.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.00)
    m = Basemap(resolution='c',projection='robin',lon_0=0)
    m.fillcontinents(color='gray',lake_color='white',zorder=2)
    coasts = m.drawcoastlines(zorder=1,color='white',linewidth=0)
    coasts_paths = coasts.get_paths()
    
    ipolygons = range(83) + [84]
    for ipoly in xrange(len(coasts_paths)):
        r = coasts_paths[ipoly]
        # Convert into lon/lat vertices
        polygon_vertices = [(vertex[0],vertex[1]) for (vertex,code) in
                            r.iter_segments(simplify=False)]
        px = [polygon_vertices[i][0] for i in xrange(len(polygon_vertices))]
        py = [polygon_vertices[i][1] for i in xrange(len(polygon_vertices))]
        if ipoly in ipolygons:
            m.plot(px,py,linewidth=0.5,zorder=3,color='black')
        else:
            m.plot(px,py,linewidth=0.5,zorder=4,color='grey')
    plt.savefig('world2.png',dpi=100)
    

    enter image description here

提交回复
热议问题