From: <js...@us...> - 2008-11-20 13:08:54
|
Revision: 6419 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6419&view=rev Author: jswhit Date: 2008-11-20 13:08:44 +0000 (Thu, 20 Nov 2008) Log Message: ----------- example showing how to re-use a map background. Modified Paths: -------------- trunk/toolkits/basemap/MANIFEST.in trunk/toolkits/basemap/examples/README Added Paths: ----------- trunk/toolkits/basemap/examples/save_background.py Modified: trunk/toolkits/basemap/MANIFEST.in =================================================================== --- trunk/toolkits/basemap/MANIFEST.in 2008-11-20 12:27:42 UTC (rev 6418) +++ trunk/toolkits/basemap/MANIFEST.in 2008-11-20 13:08:44 UTC (rev 6419) @@ -11,6 +11,7 @@ include setup.cfg include setupegg.py include src/* +include examples/save_background.py include examples/embedding_map_in_wx.py include examples/cubed_sphere.py include examples/simpletest.py Modified: trunk/toolkits/basemap/examples/README =================================================================== --- trunk/toolkits/basemap/examples/README 2008-11-20 12:27:42 UTC (rev 6418) +++ trunk/toolkits/basemap/examples/README 2008-11-20 13:08:44 UTC (rev 6419) @@ -120,3 +120,6 @@ embedding_map_in_wx.py is an example of how to embed Basemap using wx or wxagg in a GUI application. + +save_background.py shows how to save a map background and reuse it in another +figure (without having to redraw coastlines). Added: trunk/toolkits/basemap/examples/save_background.py =================================================================== --- trunk/toolkits/basemap/examples/save_background.py (rev 0) +++ trunk/toolkits/basemap/examples/save_background.py 2008-11-20 13:08:44 UTC (rev 6419) @@ -0,0 +1,36 @@ +import matplotlib +matplotlib.use('Agg') +from mpl_toolkits.basemap import Basemap +import matplotlib.pyplot as plt + +# this example shows how to save a map background and +# reuse it in another figure. + +# make sure we have all the same properties on all figs +figprops = dict(figsize=(8,6), dpi=100, facecolor='white') + +# generate the first figure. +fig1 = plt.figure(1,**figprops) +ax1 = fig1.add_subplot(111) +# create basemap instance, plot coastlines. +map = Basemap(projection='moll',lon_0=0) +map.drawcoastlines() +map.drawmapboundary(fill_color='aqua') +map.fillcontinents(color='coral',lake_color='aqua') +fig1.canvas.draw() +background = fig1.canvas.copy_from_bbox(fig1.bbox) +fig1.savefig('figure1.png', dpi=100) + + +# generate the second figure, re-using the background +# from figure 1. +fig2 = plt.figure(2,frameon=False,**figprops) +ax2 = fig2.add_subplot(111, frameon=False, xticks=[], yticks=[]) +# restore previous background. +fig2.canvas.restore_region(background) +# draw parallels and meridians on existing background. +map.drawparallels(range(-90,90,30)) +map.drawmeridians(range(-180,180,60)) +fig2.savefig('figure2.png', dpi=100) + +print 'images saved in figure1.png and figure2.png' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |