world map without rivers with matplotlib / Basemap?

后端 未结 7 675
生来不讨喜
生来不讨喜 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:24

    I frequently modify Basemap's drawcoastlines() to avoid those 'broken' rivers. I also modify drawcountries() for the sake of data source consistency.

    Here is what I use in order to support the different resolutions available in Natural Earth data:

    from mpl_toolkits.basemap import Basemap
    
    
    class Basemap(Basemap):
        """ Modify Basemap to use Natural Earth data instead of GSHHG data """
        def drawcoastlines(self):
            shapefile = 'data/naturalearth/coastline/ne_%sm_coastline' % \
                        {'l':110, 'm':50, 'h':10}[self.resolution]
            self.readshapefile(shapefile, 'coastline', linewidth=1.)
        def drawcountries(self):
            shapefile = 'data/naturalearth/countries/ne_%sm_admin_0_countries' % \
                        {'l':110, 'm':50, 'h':10}[self.resolution]
            self.readshapefile(shapefile, 'countries', linewidth=0.5)
    
    
    m = Basemap(llcrnrlon=-90, llcrnrlat=-40, urcrnrlon=-30, urcrnrlat=+20,
                resolution='l')  # resolution = (l)ow | (m)edium | (h)igh
    m.drawcoastlines()
    m.drawcountries()
    

    Here is the output:

    Please note that by default Basemap uses resolution='c' (crude), which is not supported in the code shown.

提交回复
热议问题