Basemap

1 Drawing a background

1.1 Draw coastlines, filling ocean and land areas


In [6]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
m = Basemap(width=12000000, height=4500000, projection='lcc',
           resolution='c', lat_1=45., lat_2=33, lat_0=30, lon_0=117.)
m.drawcoastlines()
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='coral',lake_color='aqua')
plt.show()


1.2 draw a land-sea mask as an image


In [10]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
m = Basemap(width=12000000, height=9000000, projection='lcc',
           resolution=None, lat_1=45,lat_2=55, lat_0=50, lon_0=117)
m.drawlsmask(land_color='coral', ocean_color='aqua', lakes=True)
plt.show()


/Users/gaufung/anaconda/lib/python3.6/site-packages/numpy/core/fromnumeric.py:224: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  return reshape(newshape, order=order)

1.3 Draw the NASA 'blue marble' image


In [1]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
m = Basemap(width=12000000, height=9000000, projection='lcc',
           resolution=None, lat_1=45,lat_2=55, lat_0=50, lon_0=117)
m.bluemarble()
plt.show()


1.4 Draw a shaded relief image.


In [3]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
m = Basemap(width=12000000,height=9000000,projection='lcc',
            resolution=None,lat_1=45.,lat_2=55,lat_0=50,lon_0=107.)
m.shadedrelief()
plt.show()


2 Drawing and labelling parallels and meridians


In [5]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
# setup Lambert Conformal basemap.
m = Basemap(width=12000000,height=9000000,projection='lcc',
            resolution='c',lat_1=45.,lat_2=55,lat_0=50,lon_0=107.)
# 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='aqua')
# fill continents, set lake color same as ocean color.
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
# label parallels on right and top
# meridians on bottom and left
parallels = np.arange(0.,81,10.)
# labels = [left,right,top,bottom]
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(10.,351.,20.)
m.drawmeridians(meridians,labels=[True,False,False,True])
plt.show()


2 Draw China Map


In [ ]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
m = Basemap(
        projection='merc', llcrnrlon=70, llcrnrlat=15,
        urcrnrlon=140, urcrnrlat=55, lat_0=15, lon_0=95, resolution='l')
#map.drawcoastlines()
x_lon = np.array([117, 118])
y_lat = np.array([35, 35])
x, y = m(x_lon, y_lat)
m.hexbin(x, y, gridsize=40, bins='log', cmap=cm.YlOrRd_r)
m.drawcountries()
m.fillcontinents(color='#C6E2FF')
#plt.title('')
plt.show()