From: <js...@us...> - 2007-11-15 18:13:07
|
Revision: 4312 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4312&view=rev Author: jswhit Date: 2007-11-15 10:13:04 -0800 (Thu, 15 Nov 2007) Log Message: ----------- new customticks.py example. Modified Paths: -------------- trunk/toolkits/basemap-testing/examples/README Added Paths: ----------- trunk/toolkits/basemap-testing/examples/customticks.py Modified: trunk/toolkits/basemap-testing/examples/README =================================================================== --- trunk/toolkits/basemap-testing/examples/README 2007-11-15 18:10:54 UTC (rev 4311) +++ trunk/toolkits/basemap-testing/examples/README 2007-11-15 18:13:04 UTC (rev 4312) @@ -10,6 +10,9 @@ contour_demo.py demonstrates the use of filled contours with map projections. +customticks.py shows how to create custom tick labels for a cylindrical +projection. + plotmap.py is the example on the matplotlib 'screenshots' page (included in test.py) which shows the ETOPO topography as an image on a Lambert Conformal projection (using imshow). Added: trunk/toolkits/basemap-testing/examples/customticks.py =================================================================== --- trunk/toolkits/basemap-testing/examples/customticks.py (rev 0) +++ trunk/toolkits/basemap-testing/examples/customticks.py 2007-11-15 18:13:04 UTC (rev 4312) @@ -0,0 +1,48 @@ +from matplotlib.toolkits.basemap import Basemap +import pylab, numpy +from matplotlib.ticker import FuncFormatter + +# example showing how to create custom tick labels for a cylindrical +# projection. + +def deg2str(deg, dir='E', fmt="%3.1f"): + min = 60 * (deg - numpy.floor(deg)) + deg = numpy.floor(deg) + if deg < 0: + if min != 0.0: + deg += 1.0 + min -= 60.0 + if dir=='E': + dir='W' + if dir=='N': + dir='S' + return (u"%d\N{DEGREE SIGN}" + fmt + "' %s") % (numpy.abs(deg), numpy.abs(min), dir) + +# 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. +m.drawcoastlines() +m.fillcontinents(color="coral") +# get axes instance. +ax = pylab.gca() +# add custom ticks. +# This only works for projection='cyl'. +def xformat(x, pos=None): return deg2str(x, 'E', fmt="%2.0f") +xformatter = FuncFormatter(xformat) +ax.xaxis.set_major_formatter(xformatter) +def yformat(y, pos=None): return deg2str(y, 'N', fmt="%2.0f") +yformatter = FuncFormatter(yformat) +ax.yaxis.set_major_formatter(yformatter) +ax.fmt_xdata = lambda x: deg2str(x, 'E', fmt="%5.3f") +ax.fmt_ydata = lambda y: deg2str(y, 'N', fmt="%5.3f") +ax.grid() +ax.set_title('Hawaii') +pylab.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2007-11-16 16:55:00
|
Revision: 4337 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4337&view=rev Author: jswhit Date: 2007-11-16 08:54:58 -0800 (Fri, 16 Nov 2007) Log Message: ----------- replace ireland.py example with hires.py Modified Paths: -------------- trunk/toolkits/basemap-testing/examples/README trunk/toolkits/basemap-testing/examples/hires.py Removed Paths: ------------- trunk/toolkits/basemap-testing/examples/ireland.py Modified: trunk/toolkits/basemap-testing/examples/README =================================================================== --- trunk/toolkits/basemap-testing/examples/README 2007-11-16 15:58:05 UTC (rev 4336) +++ trunk/toolkits/basemap-testing/examples/README 2007-11-16 16:54:58 UTC (rev 4337) @@ -25,15 +25,12 @@ nytolondon.py shows how to draw a great circle on a map (NY to London) -hires.py illustrates the use of the optional high-resolution coastlines, by -drawing the coastlines, political boundaries and rivers of the British Isles. +hires.py illustrates the use of the high-resolution coastlines, by +drawing the coastlines, political boundaries and rivers of the British +Isles. Shows how to pickle and re-load a Basemap class instance (useful +for high-res coastlines when you are plotting the same small map region +many times in different scripts). -ireland.py draws maps of ireland with the crude, low and intermediate -resolution boundary datasets. Also does high res coastlines if they -are installed. Shows how to pickle and re-load a -Basemap class instance (useful for high-res coastlines when you are plotting -the same small map region many times in different scripts). - quiver_demo.py shows how to plot wind vectors on a map. randompoints.py demonstrates the use of scatter to plot randomly distributed Modified: trunk/toolkits/basemap-testing/examples/hires.py =================================================================== --- trunk/toolkits/basemap-testing/examples/hires.py 2007-11-16 15:58:05 UTC (rev 4336) +++ trunk/toolkits/basemap-testing/examples/hires.py 2007-11-16 16:54:58 UTC (rev 4337) @@ -1,16 +1,28 @@ from matplotlib.toolkits.basemap import Basemap -from pylab import * -import time +from pylab import show, title, arange, figure, clf +import cPickle, time -# create new figure -fig=figure() -# background color will be used for 'wet' areas. -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') +# create figure with aqua background (will be oceans) +fig = figure() + # create Basemap instance. Use 'high' resolution coastlines. t1 = time.clock() m = Basemap(llcrnrlon=-11.,llcrnrlat=49.,urcrnrlon=5.,urcrnrlat=59., - resolution='h',projection='tmerc',lon_0=-8.,lat_0=0.) -print 'time to create instance with high-res boundaries = ',time.clock()-t1 + resolution='h',projection='tmerc',lon_0=-8,lat_0=0) +# make sure countries and rivers are loaded +m.drawcountries() +m.drawrivers() +print time.clock()-t1,' secs to create original Basemap instance' + +# cPickle the class instance. +cPickle.dump(m,open('map.pickle','wb'),-1) + +# 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') @@ -18,6 +30,7 @@ m.drawcountries(linewidth=1) # draw major rivers. m.drawrivers(color='b') +print time.clock()-t1,' secs to plot using using a pickled Basemap instance' # draw parallels circles = arange(48,65,2).tolist() m.drawparallels(circles,labels=[1,1,0,0]) Deleted: trunk/toolkits/basemap-testing/examples/ireland.py =================================================================== --- trunk/toolkits/basemap-testing/examples/ireland.py 2007-11-16 15:58:05 UTC (rev 4336) +++ trunk/toolkits/basemap-testing/examples/ireland.py 2007-11-16 16:54:58 UTC (rev 4337) @@ -1,144 +0,0 @@ -from matplotlib.toolkits.basemap import Basemap, basemap_datadir -from pylab import show, title, arange, figure, draw, ion, ioff, clf -import cPickle, time, sys, os - -# turn interactive mode on. -ion() -# create new figure -fig=figure() -# create Basemap instance. Use 'crude' resolution coastlines. -m = Basemap(llcrnrlon=-11.,llcrnrlat=50.5,urcrnrlon=-5.,urcrnrlat=56., - resolution='c',projection='tmerc',lon_0=-8.,lat_0=0.) -# draw coastlines and fill continents. -m.drawcoastlines() -m.fillcontinents() -# draw political boundaries. -m.drawcountries() -# draw parallels -circles = arange(50,60,1).tolist() -m.drawparallels(circles,labels=[1,1,0,0]) -# draw meridians -meridians = arange(-12,0,1) -m.drawmeridians(meridians,labels=[0,0,1,1]) -print 'plotting with crude res boundaries ...' -title("Crude Res Boundaries ('c')",y=1.05) -draw() -time.sleep(5) - -# create new figure -#fig=figure() -clf() -# create Basemap instance. Use 'low' resolution coastlines. -m = Basemap(llcrnrlon=-11.,llcrnrlat=50.5,urcrnrlon=-5.,urcrnrlat=56., - resolution='l',projection='tmerc',lon_0=-8.,lat_0=0.) -# draw coastlines and fill continents. -m.drawcoastlines() -m.fillcontinents() -# draw political boundaries. -m.drawcountries() -# draw parallels -m.drawparallels(circles,labels=[1,1,0,0]) -# draw meridians -m.drawmeridians(meridians,labels=[0,0,1,1]) -print 'plotting with low res boundaries ...' -title("Low Res Boundaries ('l')",y=1.05) -draw() -time.sleep(5) - -t1 = time.clock() -# create new figure -#fig=figure() -clf() -print 'plotting with intermediate res boundaries ...' -# create Basemap instance. Use 'intermediate' resolution coastlines. -m = Basemap(llcrnrlon=-11.,llcrnrlat=50.5,urcrnrlon=-5.,urcrnrlat=56., - resolution='i',projection='tmerc',lon_0=-8.,lat_0=0.) -print time.clock()-t1,'seconds to create class instance with intermediate res coastlines' -# cPickle the class instance. -cPickle.dump(m,open('map.pickle','wb'),-1) -# draw coastlines and fill continents. -m.drawcoastlines() -m.fillcontinents() -# draw political boundaries. -m.drawcountries() -# draw parallels -m.drawparallels(circles,labels=[1,1,0,0]) -# draw meridians -m.drawmeridians(meridians,labels=[0,0,1,1]) -title("Intermediate Res Boundaries ('i')",y=1.05) -draw() -time.sleep(5) - -# create new figure -#fig=figure() -clf() -# read cPickle back in and plot it again (should be much faster). -t1 = time.clock() -m2 = cPickle.load(open('map.pickle','rb')) -print time.clock()-t1,' to read the intermediate res coastline class instance back in from a cPickle' -# draw coastlines and fill continents. -m2.drawcoastlines() -m2.fillcontinents() -# draw political boundaries. -m2.drawcountries(linewidth=1.0) -# draw major rivers. -m2.drawrivers(color='b') -# draw parallels -m2.drawparallels(circles,labels=[1,1,0,0]) -# draw meridians -m2.drawmeridians(meridians,labels=[0,0,1,1]) -print 'plotting with intermediate res boundaries from a saved pickle ...' -title("Intermediate Res Boundaries ('i') with major rivers",y=1.05) -draw() -time.sleep(5) -# only do high-res coastlines if they are installed, otherwise stop here. -if not os.path.isfile(os.path.join(basemap_datadir,'gshhs_h.dat')): - sys.exit(0) - -import time -t1 = time.clock() -# create new figure -#fig=figure() -clf() -print 'plotting with high res boundaries ...' -# create Basemap instance. Use 'high' resolution coastlines. -m = Basemap(llcrnrlon=-11.,llcrnrlat=50.5,urcrnrlon=-5.,urcrnrlat=56., - resolution='h',projection='tmerc',lon_0=-8.,lat_0=0.) -print time.clock()-t1,'seconds to create class instance with high res coastlines' -# cPickle the class instance. -cPickle.dump(m,open('map.pickle','wb'),-1) -# draw coastlines and fill continents. -m.drawcoastlines() -m.fillcontinents() -# draw political boundaries. -m.drawcountries() -# draw parallels -m.drawparallels(circles,labels=[1,1,0,0]) -# draw meridians -m.drawmeridians(meridians,labels=[0,0,1,1]) -title("High Res Boundaries ('i')",y=1.05) -draw() -time.sleep(5) - -# create new figure -#fig=figure() -clf() -# read cPickle back in and plot it again (should be much faster). -t1 = time.clock() -m2 = cPickle.load(open('map.pickle','rb')) -print time.clock()-t1,' to read the high res coastline class instance back in from a cPickle' -# draw coastlines and fill continents. -m2.drawcoastlines() -m2.fillcontinents() -# draw political boundaries. -m2.drawcountries(linewidth=1.0) -# draw major rivers. -m2.drawrivers(color='b') -# draw parallels -m2.drawparallels(circles,labels=[1,1,0,0]) -# draw meridians -m2.drawmeridians(meridians,labels=[0,0,1,1]) -print 'plotting with high res boundaries from a saved pickle ...' -title("High Res Boundaries ('i') with major rivers",y=1.05) -ioff() -show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2007-11-17 13:08:07
|
Revision: 4349 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4349&view=rev Author: jswhit Date: 2007-11-17 05:08:05 -0800 (Sat, 17 Nov 2007) Log Message: ----------- plot two maps Modified Paths: -------------- trunk/toolkits/basemap-testing/examples/geos_demo.py trunk/toolkits/basemap-testing/examples/ortho_demo.py Modified: trunk/toolkits/basemap-testing/examples/geos_demo.py =================================================================== --- trunk/toolkits/basemap-testing/examples/geos_demo.py 2007-11-17 12:55:16 UTC (rev 4348) +++ trunk/toolkits/basemap-testing/examples/geos_demo.py 2007-11-17 13:08:05 UTC (rev 4349) @@ -1,9 +1,14 @@ from matplotlib.toolkits.basemap import Basemap -from pylab import title, show, arange +from pylab import title, show, arange, figure + # create Basemap instance for Geostationary (satellite view) projection. lon_0 = float(raw_input('enter reference longitude (lon_0):')) -h = float(raw_input('enter satellite height above equator in meters (satellite_height):')) -m = Basemap(projection='geos',lon_0=lon_0,satellite_height=h,rsphere=(6378137.00,6356752.3142),) +#h = float(raw_input('enter satellite height above equator in meters (satellite_height):')) +h = 35785831.0 + +# map with land/sea mask plotted +fig=figure() +m = Basemap(projection='geos',lon_0=lon_0,satellite_height=h,rsphere=(6378137.00,6356752.3142),resolution=None) # plot land-sea mask. rgba_land = (0,255,0,255) # land green. rgba_ocean = (0,0,255,255) # ocean blue. @@ -14,4 +19,17 @@ m.drawmeridians(arange(0.,420.,60.)) m.drawmapboundary() title('Geostationary Map Centered on Lon=%s, Satellite Height=%s' % (lon_0,h)) + +# map with continents drawn and filled. +fig = figure() +m = Basemap(projection='geos',lon_0=lon_0,satellite_height=h,rsphere=(6378137.00,6356752.3142),resolution='l') +m.drawcoastlines() +m.fillcontinents(color='coral') +m.drawcountries() +# draw parallels and meridians. +m.drawparallels(arange(-90.,120.,30.)) +m.drawmeridians(arange(0.,420.,60.)) +m.drawmapboundary() +title('Geostationary Map Centered on Lon=%s, Satellite Height=%s' % (lon_0,h)) show() +show() Modified: trunk/toolkits/basemap-testing/examples/ortho_demo.py =================================================================== --- trunk/toolkits/basemap-testing/examples/ortho_demo.py 2007-11-17 12:55:16 UTC (rev 4348) +++ trunk/toolkits/basemap-testing/examples/ortho_demo.py 2007-11-17 13:08:05 UTC (rev 4349) @@ -1,9 +1,13 @@ from matplotlib.toolkits.basemap import Basemap -from pylab import title, show, arange +from pylab import title, show, arange, figure + # create Basemap instance for Orthographic (satellite view) projection. lon_0 = float(raw_input('enter reference longitude (lon_0):')) lat_0 = float(raw_input('enter reference latitude (lat_0):')) -m = Basemap(projection='ortho',lon_0=lon_0,lat_0=lat_0) + +# map with land/sea mask plotted +fig = figure() +m = Basemap(projection='ortho',lon_0=lon_0,lat_0=lat_0,resolution=None) # plot land-sea mask. rgba_land = (0,255,0,255) # land green. rgba_ocean = (0,0,255,255) # ocean blue. @@ -14,4 +18,16 @@ m.drawmeridians(arange(0.,420.,60.)) m.drawmapboundary() title('Orthographic Map Centered on Lon=%s, Lat=%s' % (lon_0,lat_0)) + +# map with continents drawn and filled. +fig = figure() +m = Basemap(projection='ortho',lon_0=lon_0,lat_0=lat_0,resolution='l') +m.drawcoastlines() +m.fillcontinents(color='coral') +m.drawcountries() +# draw parallels and meridians. +m.drawparallels(arange(-90.,120.,30.)) +m.drawmeridians(arange(0.,420.,60.)) +m.drawmapboundary() +title('Orthographic Map Centered on Lon=%s, Lat=%s' % (lon_0,lat_0)) show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |