Revision: 7561
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7561&view=rev
Author: jswhit
Date: 2009-08-24 22:34:25 +0000 (Mon, 24 Aug 2009)
Log Message:
-----------
add nightshade method to Basemap base class.
Modified Paths:
--------------
trunk/toolkits/basemap/examples/daynight.py
Modified: trunk/toolkits/basemap/examples/daynight.py
===================================================================
--- trunk/toolkits/basemap/examples/daynight.py 2009-08-24 22:20:10 UTC (rev
7560)
+++ trunk/toolkits/basemap/examples/daynight.py 2009-08-24 22:34:25 UTC (rev
7561)
@@ -1,5 +1,5 @@
import numpy as np
-from mpl_toolkits.basemap import Basemap, netcdftime, shiftgrid
+from mpl_toolkits.basemap import Basemap, netcdftime
import matplotlib.pyplot as plt
from datetime import datetime
from numpy import ma
@@ -63,11 +63,21 @@
daynight = ma.array(daynight,mask=1-daynight) # mask day areas.
return lons2,lats2,daynight
+class Basemap2(Basemap):
+ def nightshade(self,color="0.5",nlons=1441,alpha=0.5):
+ # create grid of day=0, night=1
+ # 1441 means use a 0.25 degree grid.
+ lons,lats,daynight = daynightgrid(d,nlons)
+ x,y = self(lons,lats)
+ # contour the day-night grid, coloring the night area
+ # with the specified color and transparency.
+ return map.contourf(x,y,daynight,1,colors=[color],alpha=alpha)
+
# current time in UTC.
d = datetime.utcnow()
# miller projection
-map = Basemap(projection='mill',lon_0=0)
+map = Basemap2(projection='mill',lon_0=0)
# plot coastlines, draw label meridians and parallels.
map.drawcoastlines()
map.drawparallels(np.arange(-90,90,30),labels=[1,0,0,0])
@@ -75,12 +85,8 @@
# fill continents 'coral' (with zorder=0), color wet areas 'aqua'
map.drawmapboundary(fill_color='aqua')
map.fillcontinents(color='coral',lake_color='aqua',zorder=0)
-# create grid of day=0, night=1
-# 1441 means use a 0.25 degree grid.
-lons,lats,daynight = daynightgrid(d,1441)
-x,y = map(lons, lats)
-# contour this grid with 1 contour level, specifying color for night areas.
-# Use alpha transparency so map shows through.
-CS=map.contourf(x,y,daynight,1,colors=['0.5'],alpha=0.5)
+# shade the night areas gray, with alpha transparency so the
+# map shows through.
+map.nightshade(color="0.5",nlons=1441,alpha=0.5)
plt.title('Day/Night Map for %s (UTC)' %d )
plt.show()
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins