| |
- 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 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.2.1 (20050410)
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),
'l' (low), or 'i' (intermediate). 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).
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).
- drawgreatcircle(self, ax, lon1, lat1, lon2, lat2, dtheta=0.02, color='k', linewidth=1.0, linestyle='-', dashes=[None, None])
- draw a great circle on the map.
ax - current axis instance.
lon1,lat1 - longitude,latitude of one endpoint of the great circle.
lon2,lat2 - longitude,latitude of the other endpoint of the great circle.
dtheta - interval between points on arc in radians (default=0.02).
color - color to draw great circle (default black).
linewidth - line width for great circle (default 1.)
linestyle - line style for great circle (default '-', i.e. solid).
dashes - dash pattern for great circle (default [None,None], i.e. solid).
Note: cannot handle situations in which the great circle intersects
the edge of the map projection domain, and then re-enters the domain.
- drawmeridians(self, ax, meridians, color='k', linewidth=1.0, linestyle='--', dashes=[1, 1], labels=[0, 0, 0, 0], font='rm', fontsize=12)
- 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).
labels - list of 4 values (default [0,0,0,0]) that control whether
meridians are labelled where they intersect the left, right, top or
bottom of the plot. For example labels=[1,0,0,1] will cause meridians
to be labelled where they intersect the left and bottom of the plot,
but not the right and top. Labels are drawn using mathtext.
font - mathtext font used for labels ('rm','tt','it' or 'cal', default 'rm').
fontsize - font size in points for labels (default 12).
- drawparallels(self, ax, circles, color='k', linewidth=1.0, linestyle='--', dashes=[1, 1], labels=[0, 0, 0, 0], font='rm', fontsize=12)
- 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).
labels - list of 4 values (default [0,0,0,0]) that control whether
parallels are labelled where they intersect the left, right, top or
bottom of the plot. For example labels=[1,0,0,1] will cause parallels
to be labelled where they intersect the left and bottom of the plot,
but not the right and top. Labels are drawn using mathtext.
font - mathtext font used for labels ('rm','tt','it' or 'cal', default 'rm').
fontsize - font size in points for labels (default 12).
- 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).
- gcpoints(self, lon1, lat1, lon2, lat2, npoints)
- compute npoints points along a great circle with endpoints
(lon1,lat1) and (lon2,lat2). Returns numarrays x,y
with map projection coordinates.
- makegrid(self, nx, ny)
- return arrays of shape (ny,nx) containing lon,lat coordinates of
an equally spaced native projection grid.
| |