| |
- Basemap
class Basemap |
|
Set up a basemap with a given map projection (cylindrical equidistant,
mercator, lambert conformal conic, lambert azimuthal equal area,
albers equal area conic and stereographic are currently available).
Doesn't actually draw anything, but sets up the map projection class and
creates the coastline and political boundary polygons in native map
projection coordinates. Requires matplotlib and numarray.
Uses a pyrex interface to C-code from proj.4 (http://proj.maptools.org).
Useful instance variables:
projection - map projection ('cyl','merc','lcc','aea','laea' or 'stere')
aspect - map aspect ratio (size of y dimension / size of x dimension).
llcrnrlon - longitude of lower left hand corner of the desired map domain.
llcrnrlon - latitude of lower left hand corner of the desired map domain.
urcrnrlon - longitude of upper right hand corner of the desired map domain.
urcrnrlon - latitude of upper right hand corner of the desired map domain.
llcrnrx,llcrnry,urcrnrx,urcrnry - corners of map domain in projection coordinates.
Example Usage:
(this example plus others can be run by running test.py in the examples dir)
>>> from matplotlib.toolkits.basemap import Basemap
>>> import cPickle
>>> from pylab import *
>>> # read in topo data from pickle (on a regular lat/lon grid)
>>> topodict = cPickle.load(open('etopo20.pickle','rb'))
>>> etopo = topodict['data']; lons = topodict['lons']; lats = topodict['lats']
>>> m = Basemap(lons[0],lats[0],lons[-1],lats[-1])
>>> xsize = rcParams['figure.figsize'][0]
>>> fig=figure(figsize=(xsize,m.aspect*xsize))
>>> fig.add_axes([0.1,0.1,0.8,0.8])
>>> im = imshow(etopo,extent=(m.llcrnrx,m.urcrnrx,m.llcrnry,m.urcrnry),origin='lower')
>>> ax = gca() # get current axis instance
>>> # draw coastlines and fill continents.
>>> m.drawcoastlines(ax)
>>> m.fillcontinents(ax)
>>> # draw parallels
>>> circles = arange(-90.,120.,30.)
>>> m.drawparallels(ax,circles)
>>> # draw meridians
>>> meridians = arange(0.,390.,60.)
>>> m.drawmeridians(ax,meridians)
>>> ax.set_xticks([]) # no ticks
>>> ax.set_yticks([])
>>> title('Cylindrical Equidistant')
>>> show()
Version: 0.1 (20050203)
Contact: Jeff Whitaker <jeffrey.s.whitaker@noaa.gov> |
|
Methods defined here:
- __call__(self, x, y, inverse=False)
- Calling a Basemap class instance with the arguments lon, lat will
convert lon/lat (in degrees) to x/y native map projection
coordinates (in meters). If optional keyword 'inverse' is
True (default is False), the inverse transformation from x/y
to lon/lat is performed.
For cylindrical equidistant projection ('cyl'), this
does nothing (i.e. x,y == lon,lat).
For mercator projection ('merc'), x == lon, but y has units
of meters.
lon,lat can be either scalar floats or N arrays.
- __init__(self, llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat, resolution='c', area_thresh=10000.0, projection='cyl', rsphere=6371009.0, lat_ts=None, lat_1=None, lat_2=None, lat_0=None, lon_0=None)
- create a Basemap instance.
mandatory input arguments:
llcrnrlon - longitude of lower left hand corner of the desired map domain.
llcrnrlon - latitude of lower left hand corner of the desired map domain.
urcrnrlon - longitude of upper right hand corner of the desired map domain.
urcrnrlon - latitude of upper right hand corner of the desired map domain.
optional keyword parameters:
resolution - resolution of coastline database to use. Can be 'c' (crude,
roughly 25 km resolution) or 'l' (low, roughly 5 km resolution). Default 'c'.
Coastline data is from the GSHHS
(http://www.soest.hawaii.edu/wessel/gshhs/gshhs.html).
area_thresh - coastline with an area smaller than area_thresh in km^2
will not be plotted. Default 10,000.
projection - map projection. 'cyl' - cylindrical equidistant, 'merc' -
mercator, 'lcc' - lambert conformal conic, 'stere' - stereographic,
'aea' - albers equal area conic, and
'laea' - lambert azimuthal equal area currently available. Default 'cyl'.
rsphere - radius of the sphere used to define map projection (default
6371009 meters, close to the arithmetic mean radius of the earth).
The following parameters are map projection parameters which all default to
None. Not all parameters are used by all projections, some are ignored.
lat_ts - latitude of natural origin (used for mercator and stereographic
projections).
lat_1 - first standard parallel for lambert conformal and albers
equal area projections.
lat_2 - second standard parallel for lambert conformal and albers
equal area projections.
lat_0 - central latitude (y-axis origin) - used by stereographic and
lambert azimuthal projections).
lon_0 - central meridian (x-axis origin - used by lambert conformal
and lambert azimuthal and stereographic projections).
- drawcoastlines(self, ax, linewidth=1.0, color='k', antialiased=1)
- Draw coastlines.
ax - current axis instance.
linewidth - coastline width (default 1.)
color - coastline color (default black)
antialiased - antialiasing switch for coastlines (default True).
- drawcountries(self, ax, linewidth=0.5, color='k', antialiased=1)
- Draw country boundaries.
ax - current axis instance.
linewidth - country boundary line width (default 0.5)
color - country boundary line color (default black)
antialiased - antialiasing switch for country boundaries (default True).
- drawmeridians(self, ax, meridians, color='k', linewidth=1.0, linestyle='--', dashes=[1, 1])
- draw meridians (longitude lines).
ax - current axis instance.
meridians - list containing longitude values to draw (in degrees).
color - color to draw meridians (default black).
linewidth - line width for meridians (default 1.)
linestyle - line style for meridians (default '--', i.e. dashed).
dashes - dash pattern for meridians (default [1,1], i.e. 1 pixel on,
1 pixel off).
- drawparallels(self, ax, circles, color='k', linewidth=1.0, linestyle='--', dashes=[1, 1])
- draw parallels (latitude lines).
ax - current axis instance.
circles - list containing latitude values to draw (in degrees).
color - color to draw parallels (default black).
linewidth - line width for parallels (default 1.)
linestyle - line style for parallels (default '--', i.e. dashed).
dashes - dash pattern for parallels (default [1,1], i.e. 1 pixel on,
1 pixel off).
- drawstates(self, ax, linewidth=0.5, color='k', antialiased=1)
- Draw state boundaries in Americas.
ax - current axis instance.
linewidth - state boundary line width (default 0.5)
color - state boundary line color (default black)
antialiased - antialiasing switch for state boundaries (default True).
- fillcontinents(self, ax, color=0.80000000000000004)
- Fill continents.
ax - current axis instance.
color - color to fill continents (default gray).
- makegrid(self, nx, ny)
- return arrays of shape (ny,nx) containing lon,lat coordinates of
an equally spaced native projection grid.
| |