From: <js...@us...> - 2010-06-10 18:25:25
|
Revision: 8409 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8409&view=rev Author: jswhit Date: 2010-06-10 18:25:19 +0000 (Thu, 10 Jun 2010) Log Message: ----------- don't force adjustable='box' for AxesGrid compatability. Added example that uses AxesGrid. Modified Paths: -------------- trunk/toolkits/basemap/Changelog trunk/toolkits/basemap/MANIFEST.in trunk/toolkits/basemap/examples/README trunk/toolkits/basemap/examples/run_all.py trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py Added Paths: ----------- trunk/toolkits/basemap/examples/fcstmaps_axesgrid.py Modified: trunk/toolkits/basemap/Changelog =================================================================== --- trunk/toolkits/basemap/Changelog 2010-06-10 17:48:10 UTC (rev 8408) +++ trunk/toolkits/basemap/Changelog 2010-06-10 18:25:19 UTC (rev 8409) @@ -1,4 +1,6 @@ version 0.99.5 (not yet released) + * don't force adjustable='box' so Basemap is compatible + with AxesGrid. Added fcstmaps_axesgrid.py example. * add support for plotting on unstructured grids using keyword 'tri' in pcolor,contour,contourf methods (which then forward to tripcolor, tricontour, tricontourf axes Modified: trunk/toolkits/basemap/MANIFEST.in =================================================================== --- trunk/toolkits/basemap/MANIFEST.in 2010-06-10 17:48:10 UTC (rev 8408) +++ trunk/toolkits/basemap/MANIFEST.in 2010-06-10 18:25:19 UTC (rev 8409) @@ -53,6 +53,7 @@ include examples/geos_demo_3.py include examples/200706041200-msg-ch01-SAfrica.jpg include examples/fcstmaps.py +include examples/fcstmaps_axesgrid.py include examples/plotsst.py include examples/wiki_example.py include examples/fillstates.py Modified: trunk/toolkits/basemap/examples/README =================================================================== --- trunk/toolkits/basemap/examples/README 2010-06-10 17:48:10 UTC (rev 8408) +++ trunk/toolkits/basemap/examples/README 2010-06-10 18:25:19 UTC (rev 8409) @@ -63,6 +63,9 @@ fcstmaps.py is a sample multi-panel plot that accesses data over http using the dap module. An internet connection is required. +fcstmaps_axesgrid.py is the same as above, but illustrates the use +of the AxesGrid toolkit. + plotsst.py also uses dap client to access the data, and also illustrates how the NetCDFFile function deals with missing values. Added: trunk/toolkits/basemap/examples/fcstmaps_axesgrid.py =================================================================== --- trunk/toolkits/basemap/examples/fcstmaps_axesgrid.py (rev 0) +++ trunk/toolkits/basemap/examples/fcstmaps_axesgrid.py 2010-06-10 18:25:19 UTC (rev 8409) @@ -0,0 +1,102 @@ +# this example reads today's numerical weather forecasts +# from the NOAA OpenDAP servers and makes a multi-panel plot. +# This version demonstrates the use of the AxesGrid toolkit. +import numpy as np +import matplotlib.pyplot as plt +import sys +import numpy.ma as ma +import datetime +from mpl_toolkits.basemap import Basemap, NetCDFFile, addcyclic, num2date +from mpl_toolkits.axes_grid1 import AxesGrid + + +# today's date is default. +if len(sys.argv) > 1: + YYYYMMDD = sys.argv[1] +else: + YYYYMMDD = datetime.datetime.today().strftime('%Y%m%d') + +# set OpenDAP server URL. +URLbase="http://nomad1.ncep.noaa.gov:9090/dods/mrf/mrf" +URL=URLbase+YYYYMMDD+'/mrf'+YYYYMMDD +print URL+'\n' +try: + data = NetCDFFile(URL) +except: + msg = """ +opendap server not providing the requested data. +Try another date by providing YYYYMMDD on command line.""" + raise IOError, msg + + +# read lats,lons,times. + +print data.variables.keys() +latitudes = data.variables['lat'] +longitudes = data.variables['lon'] +fcsttimes = data.variables['time'] +times = fcsttimes[0:6] # first 6 forecast times. +ntimes = len(times) +# convert times for datetime instances. +fdates = num2date(times,units=fcsttimes.units,calendar='standard') +# make a list of YYYYMMDDHH strings. +verifdates = [fdate.strftime('%Y%m%d%H') for fdate in fdates] +# convert times to forecast hours. +fcsthrs = [] +for fdate in fdates: + fdiff = fdate-fdates[0] + fcsthrs.append(fdiff.days*24. + fdiff.seconds/3600.) +print fcsthrs +print verifdates +lats = latitudes[:] +nlats = len(lats) +lons1 = longitudes[:] +nlons = len(lons1) + +# unpack 2-meter temp forecast data. + +t2mvar = data.variables['tmp2m'] +t2min = t2mvar[0:ntimes,:,:] +t2m = np.zeros((ntimes,nlats,nlons+1),t2min.dtype) + +# create figure, set up AxesGrid. +fig=plt.figure(figsize=(6,8)) +grid = AxesGrid(fig, [0.05,0.01,0.9,0.9], + nrows_ncols=(3, 2), + axes_pad=0.25, + cbar_mode='single', + cbar_pad=0.3, + cbar_size=0.1, + cbar_location='top', + share_all=True, + ) + +# create Basemap instance for Orthographic projection. +m = Basemap(lon_0=-90,lat_0=60,projection='ortho') +# add wrap-around point in longitude. +for nt in range(ntimes): + t2m[nt,:,:], lons = addcyclic(t2min[nt,:,:], lons1) +# convert to celsius. +t2m = t2m-273.15 +# contour levels +clevs = np.arange(-30,30.1,2.) +lons, lats = np.meshgrid(lons, lats) +x, y = m(lons, lats) +# make subplots. +for nt,fcsthr in enumerate(fcsthrs): + ax = grid[nt] + m.ax = ax + cs = m.contourf(x,y,t2m[nt,:,:],clevs,cmap=plt.cm.jet,extend='both') + m.drawcoastlines(linewidth=0.5) + m.drawcountries() + m.drawparallels(np.arange(-80,81,20)) + m.drawmeridians(np.arange(0,360,20)) + # panel title + ax.set_title('%d-h forecast valid '%fcsthr+verifdates[nt],fontsize=9) +# figure title +plt.figtext(0.5,0.95, + u"2-m temp (\N{DEGREE SIGN}C) forecasts from %s"%verifdates[0], + horizontalalignment='center',fontsize=14) +# a single colorbar. +cbar = fig.colorbar(cs, cax=grid.cbar_axes[0], orientation='horizontal') +plt.show() Modified: trunk/toolkits/basemap/examples/run_all.py =================================================================== --- trunk/toolkits/basemap/examples/run_all.py 2010-06-10 17:48:10 UTC (rev 8408) +++ trunk/toolkits/basemap/examples/run_all.py 2010-06-10 18:25:19 UTC (rev 8409) @@ -2,6 +2,7 @@ test_files = glob.glob('*.py') test_files.remove('run_all.py') test_files.remove('fcstmaps.py') +test_files.remove('fcstmaps_axesgrid.py') test_files.remove('testgdal.py') test_files.remove('pnganim.py') test_files.remove('geos_demo_2.py') Modified: trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py =================================================================== --- trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2010-06-10 17:48:10 UTC (rev 8408) +++ trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2010-06-10 18:25:19 UTC (rev 8409) @@ -2628,9 +2628,9 @@ # plot is re-centered in bounding rectangle. # (anchor instance var determines where plot is placed) if self.fix_aspect: - ax.set_aspect('equal',adjustable='box',anchor=self.anchor) + ax.set_aspect('equal',anchor=self.anchor) else: - ax.set_aspect('auto',adjustable='box',anchor=self.anchor) + ax.set_aspect('auto',anchor=self.anchor) # make sure axis ticks are turned off. if self.noticks: ax.set_xticks([]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |