Hrafnkell Pálsson wrote: > Jeff Whitaker wrote: > >> Hrafnkell: >> >> Had some time this morning, so I used John's method to create a working >> Basemap example: >> >> 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) >> >> >> I've added this to the basemap examples directory as save_background.py >> >> HTH, >> >> -Jeff >> >> > > There's still one snag. > Using your example I could restore the background. > But it turns out everything is plotted over the background; so if my > background consist only of the coastline and then I do a filled contour plot > after restoring it the coastline disappears under the filled contours (by > using the alpha keyword to contourf I could see the coastline beneath). > > Had I plotted the coastline into the figure instead of restoring it this > would not have happened. > > Is there any way of avoiding this? > > Hrafnkell > > > >
Hrafnkell: I see your point, but I don't see any obvious solution. Perhaps someone with more knowledge of matplotlib internals (John?) can answer. -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : [EMAIL PROTECTED] 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users