整理自https://matplotlib.org/basemap/users/examples.html
- 用到的方法:
contour()
: draw contour lines.(等高线)
contourf()
: draw filled contours.
imshow()
: draw an image.
pcolor()
: draw a pseudocolor plot.(伪色图)
pcolormesh()
: draw a pseudocolor plot (faster version for regular meshes).
画一个伪颜色图(对于普通网格来说是更快的版本)。
plot()
: draw lines and/or markers.
scatter()
: draw points with markers.
quiver()
: draw vectors.
barbs()
: draw wind barbs.
drawgreatcircle()
: draw a great circle.drawcoastlines()
: draw coastlines.
-
fillcontinents()
: 为大陆内部上色。不幸的是,fillmethods并不总是正确的。Matplotlib总是试图填充多边形的内部。在某些情况下,海岸线多边形的内部可能是模糊的,外部可能被填充而不是内部。在这些情况下,推荐的解决方法是使用drawlsmask()方法,使用为陆地和水域指定的不同颜色覆盖图像(见下文)。 -
drawcountries()
: draw country boundaries. -
drawstates()
: 划定北美各州界限 -
drawrivers()
: draw rivers. -
drawlsmask()
: 绘制高分辨率陆地-海洋掩模作为图像,指定陆地和海洋的颜色。陆海掩模来自GSHHS的海岸线数据,有几种海岸线选项和像素大小可供选择。 -
drawlsmask(land_color=‘0.8’, ocean_color=‘w’, lsmask=None, lsmask_lons=None, lsmask_lats=None, lakes=True, resolution=‘l’, grid=5, **kwargs)
-
bluemarble()
: draw a NASA Blue Marble image as a map background. -
shadedrelief()
: draw a shaded relief image as a map background. -
etopo()
: draw an etopo relief image as map background. -
warpimage()
: 使用一个任意的图像作为地图背景。图像必须是全球的,从国际日期变更线向东,南极向北,以经纬线坐标覆盖整个世界。 -
warpimage(image=‘bluemarble’, scale=None, **kwargs)
-
drawmapboundary
(color=‘k’, linewidth=1.0, fill_color=None, zorder=None, ax=None) -
绘制地图投影区域的边界,可选填充区域的内部。
-
官方示例:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
# 设置50N, 100W的卫星俯视视角的正射地图投影。
# 使用低分辨率海岸线.
map = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l')
# draw coastlines, country boundaries, fill continents.
map.drawcoastlines(linewidth=0.25)
map.drawcountries(linewidth=0.25)
map.fillcontinents(color='coral',lake_color='aqua')
# draw the edge of the map projection region (the projection limb)
map.drawmapboundary(fill_color='aqua')
# draw lat/lon grid lines every 30 degrees.
map.drawmeridians(np.arange(0,360,30))
map.drawparallels(np.arange(-90,90,30))
plt.show()
- 到此为止已经设置好基本的一个地图了
- 接下来上数据
# make up some data on a regular lat/lon grid.
nlats = 73; nlons = 145; delta = 2.*np.pi/(nlons-1)
lats = (0.5*np.pi-delta*np.indices((nlats,nlons))[0,:,:])
lons = (delta*np.indices((nlats,nlons))[1,:,:])
wave = 0.75*(np.sin(2.*lats)**8*np.cos(4.*lons))
mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.)
# compute native map projection coordinates of lat/lon grid.
x, y = map(lons*180./np.pi, lats*180./np.pi)
# contour data over the map.
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
plt.title('contour lines over filled continent background')
plt.show()