Search code examples
python-3.xmatplotlib-basemapgeography

Python Basemap: getting more detailed coastline drawing


Is there a way to get a more detailed coastline than the default in Basemap? For example, if I try to show the coast of Norway, the default plot is very coarse and a bit ugly (see figure). Any way to get a better coastline / control the coastline resolution?

Code:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np

# setup Lambert Conformal basemap.
m = Basemap(llcrnrlon=-8.0, llcrnrlat=55.5, urcrnrlon=34.5, urcrnrlat=72.0,
            lat_0="65.0", lon_0=15.0,
            projection="lcc")

# draw coastlines.
m.drawcoastlines()

# draw a boundary around the map, fill the background.
# this background will end up being the ocean color, since
# the continents will be drawn on top.
m.drawmapboundary(fill_color="#A6CAE0")

# fill continents, set lake color.
m.fillcontinents(color='grey',lake_color='lavender')

# draw parallels and meridians.
# label parallels on right and top
# meridians on bottom and left
parallels = np.arange(50.,75.,10.)
# labels = [left,right,top,bottom]
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(-10.,40,10.)
m.drawmeridians(meridians,labels=[True,False,False,True])

plt.show()

Produces:

enter image description here

Solution:

Many thanks for the solution @hemmelig :)

Changing to:

# setup Lambert Conformal basemap.
m = Basemap(llcrnrlon=-8.0, llcrnrlat=55.5, urcrnrlon=34.5, urcrnrlat=72.0,
            lat_0="65.0", lon_0=15.0,
            projection="lcc",
            resolution="l")

Produces the nicer map:

enter image description here


Solution

  • Use the resolution keyword when instancing Basemap.

    Can be c (crude), l (low), i (intermediate), h (high), f (full) or None. If None, no boundary data will be read in (and class methods such as drawcoastlines will raise an if invoked). Resolution drops off by roughly 80% between datasets. Higher res datasets are much slower to draw. Default c. Coastline data is from the GSHHS (http://www.soest.hawaii.edu/wessel/gshhs/gshhs.html). State, country and river datasets from the Generic Mapping Tools (http://gmt.soest.hawaii.edu). (from docs)