From 71b0e633d1b37e35d20bf42d41ce2c5b8200a2f2 Mon Sep 17 00:00:00 2001 From: Jeffrey Whitaker Date: Mon, 5 Mar 2012 17:14:18 -0700 Subject: [PATCH 1/3] fix logic that decides whether to draw a map boundary. --- lib/mpl_toolkits/basemap/__init__.py | 33 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/mpl_toolkits/basemap/__init__.py b/lib/mpl_toolkits/basemap/__init__.py index fbfeb12af..a8123400c 100644 --- a/lib/mpl_toolkits/basemap/__init__.py +++ b/lib/mpl_toolkits/basemap/__init__.py @@ -2820,22 +2820,23 @@ def set_axes_limits(self,ax=None): ax.update_datalim( corners ) ax.set_xlim((self.llcrnrx, self.urcrnrx)) ax.set_ylim((self.llcrnry, self.urcrnry)) - # if map boundary not yet drawn, draw it with default values. - if not self._mapboundarydrawn: - # is the map boundary already drawn on the current axes? - if self._mapboundarydrawn not in ax.patches: - # elliptical map, turn off axis_frame, draw boundary manually. - if (self.projection in ['ortho','geos','nsper','aeqd'] and - self._fulldisk) or self.round or self.projection in _pseudocyl: - # turn off axes frame. - ax.set_frame_on(False) - # first draw boundary, no fill - limb1 = self.drawmapboundary(fill_color='none') - # draw another filled patch, with no boundary. - limb2 = self.drawmapboundary(linewidth=0) - self._mapboundarydrawn = True - else: # square map, just turn on axis frame. - ax.set_frame_on(True) + # if map boundary not yet drawn for elliptical maps, draw it with default values. + if not self._mapboundarydrawn or self._mapboundarydrawn not in ax.patches: + # elliptical map, draw boundary manually. + if (self.projection in ['ortho','geos','nsper','aeqd'] and + self._fulldisk) or self.round or self.projection in _pseudocyl: + # first draw boundary, no fill + limb1 = self.drawmapboundary(fill_color='none') + # draw another filled patch, with no boundary. + limb2 = self.drawmapboundary(linewidth=0) + self._mapboundarydrawn = limb2 + # for elliptical map, always turn off axis_frame. + if (self.projection in ['ortho','geos','nsper','aeqd'] and + self._fulldisk) or self.round or self.projection in _pseudocyl: + # turn off axes frame. + ax.set_frame_on(False) + else: # square map, always turn on axis frame. + ax.set_frame_on(True) # make sure aspect ratio of map preserved. # plot is re-centered in bounding rectangle. # (anchor instance var determines where plot is placed) From d324703972c3d51f39af47f0c0f0830dd9cfb7f7 Mon Sep 17 00:00:00 2001 From: Jeffrey Whitaker Date: Mon, 5 Mar 2012 17:14:43 -0700 Subject: [PATCH 2/3] set fill_color in drawmapboundary --- examples/nsper_demo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/nsper_demo.py b/examples/nsper_demo.py index 3259e22b2..77d099cff 100644 --- a/examples/nsper_demo.py +++ b/examples/nsper_demo.py @@ -19,7 +19,7 @@ # draw parallels and meridians. m.drawparallels(np.arange(-90.,120.,10.)) m.drawmeridians(np.arange(0.,420.,20.)) -m.drawmapboundary() +m.drawmapboundary(fill_color='aqua') plt.title('Near-Sided Perspective Map Centered on Lon=%s, Lat=%s, H=%g' %\ (lon_0,lat_0,h/1000.),fontsize=10) @@ -36,7 +36,6 @@ # draw parallels and meridians. m.drawparallels(np.arange(-90.,120.,30.)) m.drawmeridians(np.arange(0.,420.,60.)) -m.drawmapboundary() plt.title('Near-Sided Perspective Map Centered on Lon=%s, Lat=%s, H=%g' %\ (lon_0,lat_0,h/1000.),fontsize=10) From 53eb5bdd43a7987813046f30e4f040e8d219ec2a Mon Sep 17 00:00:00 2001 From: Jeffrey Whitaker Date: Mon, 5 Mar 2012 17:17:13 -0700 Subject: [PATCH 3/3] fix example. --- doc/users/figures/plotsst.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/doc/users/figures/plotsst.py b/doc/users/figures/plotsst.py index 9b34dacdc..37e6af111 100644 --- a/doc/users/figures/plotsst.py +++ b/doc/users/figures/plotsst.py @@ -2,20 +2,16 @@ from netCDF4 import Dataset, date2index, num2date import numpy as np import matplotlib.pyplot as plt -import datetime -# create datetime object for desired time -date = datetime.datetime(2007,12,15,0) -# open dataset. -dataset =\ -Dataset('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst2/totalAmsrAgg') -# find index of desired time. -time = dataset.variables['time'] -nt = date2index(date, time, calendar='standard') +date = '20071215' # date to plot. +# open dataset for that date. +dataset = \ +Dataset('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst2/%s/AVHRR-AMSR/amsr-avhrr-v2.%s.nc'%\ + (date[0:4],date)) # read sst. Will automatically create a masked array using -# missing_value variable attribute. -sst = dataset.variables['sst'][nt] +# missing_value variable attribute. 'squeeze out' singleton dimensions. +sst = dataset.variables['sst'][:].squeeze() # read ice. -ice = dataset.variables['ice'][nt] +ice = dataset.variables['ice'][:].squeeze() # read lats and lons (representing centers of grid boxes). lats = dataset.variables['lat'][:] lons = dataset.variables['lon'][:] @@ -28,7 +24,7 @@ lats = (lats - 0.5*delat).tolist() lats.append(lats[-1]+delat) lats = np.array(lats,np.float64) -# creat figure, axes instances. +# create figure, axes instances. fig = plt.figure() ax = fig.add_axes([0.05,0.05,0.9,0.9]) # create Basemap instance for Robinson projection. @@ -51,4 +47,4 @@ cb = m.colorbar(im1,"bottom", size="5%", pad="2%") # add a title. ax.set_title('SST and ICE analysis for %s'%date) -plt.savefig('plotsst.png') +plt.show()