matplotlib.toolkits.basemap. Basemap overlays?

Hello users,

I'm using matplotlib.toolkits.basemap.Basemap to plot data on several types of projections at a regular cadence. I am presently regenerating the maps each time new data is to be plotted. Is it possible to generate template map projections once (at startup) and reuse them each time new data is to be plotted? If so, could someone point to a reference or example of how to do this?

Thanks,
-- jv

Jim Vickroy wrote:

Hello users,

I'm using matplotlib.toolkits.basemap.Basemap to plot data on several types of projections at a regular cadence. I am presently regenerating the maps each time new data is to be plotted. Is it possible to generate template map projections once (at startup) and reuse them each time new data is to be plotted? If so, could someone point to a reference or example of how to do this?

Thanks,
-- jv
  
Jim: You can reuse a Basemap instance to plot data on multiple figures, like this

# create the first figure
fig = pylab.figure()
# create a Basemap instance for your map projection
map = Basemap(...)
# plot some stuff on this map projection.
map.contour(...)
... some other plotting commands ...
# save the figure
pylab.savefig('plot1.png')

# create another figure
fig = pylab.figure()
# use the same basemap instance to different data on this map projection
map.contour(...)
... more plotting commands...
# save the second figure
pylab.savefig('plot2.png')

You can also save the Basemap instance to disk using the Pickle module and reload it in another script.

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

You could try to pickle the basemap instance, that should save you some
initialization time. Then, it's just a matter of replotting.

···

On Wednesday 23 January 2008 14:57:26 Jim Vickroy wrote:

Hello users,

I'm using matplotlib.toolkits.basemap.Basemap to plot data on several
types of projections at a regular cadence. I am presently regenerating
the maps each time new data is to be plotted. Is it possible to
generate template map projections once (at startup) and reuse them each
time new data is to be plotted? If so, could someone point to a
reference or example of how to do this?

Jeff Whitaker wrote:

Jim Vickroy wrote:

Hello users,

I'm using matplotlib.toolkits.basemap.Basemap to plot data on several types of projections at a regular cadence. I am presently regenerating the maps each time new data is to be plotted. Is it possible to generate template map projections once (at startup) and reuse them each time new data is to be plotted? If so, could someone point to a reference or example of how to do this?

Thanks,
-- jv
  
Jim: You can reuse a Basemap instance to plot data on multiple figures, like this

# create the first figure
fig = pylab.figure()
# create a Basemap instance for your map projection
map = Basemap(...)
# plot some stuff on this map projection.
map.contour(...)
... some other plotting commands ...
# save the figure
pylab.savefig('plot1.png')

# create another figure
fig = pylab.figure()
# use the same basemap instance to different data on this map projection
map.contour(...)
... more plotting commands...
# save the second figure
pylab.savefig('plot2.png')

You can also save the Basemap instance to disk using the Pickle module and reload it in another script.

-Jeff

Thanks for the detailed explanation; I may be starting to understand the significance of *figure*.

I was hoping to avoid repeated calls like map.drawcoastlines(), map.drawcountries(), map.fillcontinents(color='0.95'), map.drawmapboundary(), map.drawmeridians(plot.arange(0,360,30)), and map.drawparallels(plot.arange(-90,90,30)). So, I will follow your example and experiment to see what works and what does not to better understand the behaviors.

-- jv