Revision: 4430
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4430&view=rev
Author: jswhit
Date: 2007-11-24 05:25:06 -0800 (Sat, 24 Nov 2007)
Log Message:
-----------
use drawmapboundary to fill map projection region
a specified color. Useful for painting ocean areas
(instead of setting axis background color, which only
works for rectangular projections).
Modified Paths:
--------------
trunk/toolkits/basemap/Changelog
trunk/toolkits/basemap/examples/customticks.py
trunk/toolkits/basemap/examples/hires.py
trunk/toolkits/basemap/examples/ortho_demo.py
trunk/toolkits/basemap/examples/randompoints.py
trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
Modified: trunk/toolkits/basemap/Changelog
===================================================================
--- trunk/toolkits/basemap/Changelog 2007-11-23 18:07:27 UTC (rev 4429)
+++ trunk/toolkits/basemap/Changelog 2007-11-24 13:25:06 UTC (rev 4430)
@@ -1,3 +1,5 @@
+ * add 'fill_color' option to drawmapboundary, to optionally
+ fill the map projection background a certain color.
* added 'sstanom' colormap from
http://www.ghrsst-pp.org/GHRSST-PP-Data-Tools.html
version 0.9.7 (svn revision 4422)
Modified: trunk/toolkits/basemap/examples/customticks.py
===================================================================
--- trunk/toolkits/basemap/examples/customticks.py 2007-11-23 18:07:27 UTC
(rev 4429)
+++ trunk/toolkits/basemap/examples/customticks.py 2007-11-24 13:25:06 UTC
(rev 4430)
@@ -20,17 +20,17 @@
# create figure.
fig=pylab.figure()
-# background color will be used for 'wet' areas.
-fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
# create Basemap instance (regular lat/lon projection).
# suppress_ticks=False allows custom axes ticks to be used
# Ticks are suppressed by default, so Basemap methods
# drawparallels and drawmeridians used to draw labelled lat/lon grid.
m = Basemap(llcrnrlon=-156.5,llcrnrlat=18.75,urcrnrlon=-154.5,urcrnrlat=20.5,
resolution='h',projection='cyl',suppress_ticks=False)
-# draw coastlines, fill land areas.
+# draw coastlines, fill land and lake areas.
m.drawcoastlines()
-m.fillcontinents(color="coral")
+m.fillcontinents(color='coral',lake_color='aqua')
+# background color will be used for oceans.
+m.drawmapboundary(fill_color='aqua')
# get axes instance.
ax = pylab.gca()
# add custom ticks.
Modified: trunk/toolkits/basemap/examples/hires.py
===================================================================
--- trunk/toolkits/basemap/examples/hires.py 2007-11-23 18:07:27 UTC (rev
4429)
+++ trunk/toolkits/basemap/examples/hires.py 2007-11-24 13:25:06 UTC (rev
4430)
@@ -21,15 +21,18 @@
# clear the figure
clf()
-ax = fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
# read cPickle back in and plot it again (should be much faster).
t1 = time.clock()
m2 = cPickle.load(open('map.pickle','rb'))
# draw coastlines and fill continents.
m.drawcoastlines()
-m.fillcontinents(color='coral')
+# fill continents and lakes
+m.fillcontinents(color='coral',lake_color='aqua')
# draw political boundaries.
m.drawcountries(linewidth=1)
+# fill map projection region light blue (this will
+# paint ocean areas same color as lakes).
+m.drawmapboundary(fill_color='aqua')
# draw major rivers.
m.drawrivers(color='b')
print time.clock()-t1,' secs to plot using using a pickled Basemap instance'
Modified: trunk/toolkits/basemap/examples/ortho_demo.py
===================================================================
--- trunk/toolkits/basemap/examples/ortho_demo.py 2007-11-23 18:07:27 UTC
(rev 4429)
+++ trunk/toolkits/basemap/examples/ortho_demo.py 2007-11-24 13:25:06 UTC
(rev 4430)
@@ -23,11 +23,11 @@
fig = figure()
m = Basemap(projection='ortho',lon_0=lon_0,lat_0=lat_0,resolution='l')
m.drawcoastlines()
-m.fillcontinents(color='coral')
+m.fillcontinents(color='coral',lake_color='aqua')
m.drawcountries()
# draw parallels and meridians.
m.drawparallels(arange(-90.,120.,30.))
m.drawmeridians(arange(0.,420.,60.))
-m.drawmapboundary()
+m.drawmapboundary(fill_color='aqua')
title('Orthographic Map Centered on Lon=%s, Lat=%s' % (lon_0,lat_0))
show()
Modified: trunk/toolkits/basemap/examples/randompoints.py
===================================================================
--- trunk/toolkits/basemap/examples/randompoints.py 2007-11-23 18:07:27 UTC
(rev 4429)
+++ trunk/toolkits/basemap/examples/randompoints.py 2007-11-24 13:25:06 UTC
(rev 4430)
@@ -24,8 +24,6 @@
# plot them as filled circles on the map.
# first, create a figure.
fig=figure()
-# background color will be used for 'wet' areas.
-fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
# draw colored markers.
# use zorder=10 to make sure markers are drawn last.
# (otherwise they are covered up when continents are filled)
@@ -39,9 +37,11 @@
if xpt > m.xmin and xpt < m.xmax and ypt > m.ymin and ypt < m.ymax:
hexcolor = rgb2hex(cm.jet(zval/100.)[:3])
text(xpt,ypt,numstr,fontsize=9,weight='bold',color=hexcolor)
-# draw coasts and fill continents.
+# draw coasts and fill continents/lakes.
m.drawcoastlines(linewidth=0.5)
-m.fillcontinents(color='coral')
+m.fillcontinents(color='coral',lake_color='aqua')
+# color ocean areas
+m.drawmapboundary(fill_color='aqua')
# draw parallels and meridians.
delat = 20.
circles = arange(0.,90.,delat).tolist()+\
Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
===================================================================
--- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
2007-11-23 18:07:27 UTC (rev 4429)
+++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
2007-11-24 13:25:06 UTC (rev 4430)
@@ -962,11 +962,20 @@
return boundaryll, boundaryxy
- def drawmapboundary(self,color='k',linewidth=1.0,ax=None):
+ def drawmapboundary(self,color='k',linewidth=1.0,fill_color=None,\
+ zorder=None,ax=None):
"""
- draw boundary around map projection region. If ax=None (default),
- default axis instance is used, otherwise specified axis
- instance is used.
+ draw boundary around map projection region, optionally
+ filling interior of region.
+
+ linewidth - line width for boundary (default 1.)
+ color - color of boundary line (default black)
+ fill_color - fill the map region background with this
+ color (default is no fill or fill with axis background color).
+ zorder - sets the zorder for filling map background
+ (default 0).
+ ax - axes instance to use (default None, use default axes
+ instance).
"""
# get current axes instance (if none specified).
if ax is None and self.ax is None:
@@ -981,18 +990,30 @@
# define a circle patch, add it to axes instance.
circle = Circle((self.rmajor,self.rmajor),self.rmajor)
ax.add_patch(circle)
- circle.set_fill(False)
+ if fill_color is None:
+ circle.set_fill(False)
+ else:
+ circle.set_facecolor(fill_color)
+ circle.set_zorder(0)
circle.set_edgecolor(color)
circle.set_linewidth(linewidth)
circle.set_clip_on(False)
+ if zorder is not None:
+ circle.set_zorder(zorder)
elif self.projection == 'geos' and self._fulldisk: # elliptical region
# define an Ellipse patch, add it to axes instance.
ellps =
Ellipse((self._width,self._height),2.*self._width,2.*self._height)
ax.add_patch(ellps)
- ellps.set_fill(False)
+ if fill_color is None:
+ ellps.set_fill(False)
+ else:
+ ellps.set_facecolor(fill_color)
+ ellps.set_zorder(0)
ellps.set_edgecolor(color)
ellps.set_linewidth(linewidth)
ellps.set_clip_on(False)
+ if zorder is not None:
+ ellps.set_zorder(0)
elif self.projection in ['moll','robin','sinu']: # elliptical region.
nx = 100; ny = 100
# quasi-elliptical region.
@@ -1015,13 +1036,25 @@
xy = zip(x,y)
poly = Polygon(xy,edgecolor=color,linewidth=linewidth)
ax.add_patch(poly)
- poly.set_fill(False)
+ if fill_color is None:
+ poly.set_fill(False)
+ else:
+ poly.set_facecolor(fill_color)
+ poly.set_zorder(0)
poly.set_clip_on(False)
+ if zorder is not None:
+ poly.set_zorder(zorder)
else: # all other projections are rectangular.
ax.axesPatch.set_linewidth(linewidth)
- ax.axesPatch.set_facecolor(ax.get_axis_bgcolor())
+ if fill_color is None:
+ ax.axesPatch.set_facecolor(ax.get_axis_bgcolor())
+ else:
+ ax.axesPatch.set_facecolor(fill_color)
+ ax.axesPatch.set_zorder(0)
ax.axesPatch.set_edgecolor(color)
ax.set_frame_on(True)
+ if zorder is not None:
+ ax.axesPatch.set_zorder(zorder)
# set axes limits to fit map region.
self.set_axes_limits(ax=ax)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins