Hello users,I wish to repeatedly re-plot labels and contour data on a figure since redrawing the figure is temporally expensive. The attached script (I apologize for its length), hopefully, illustrates a simplified version of what I'm trying to do -- contour temporally-varying data on a map projection.
I do not understand how to erase the plot label each time the figure is to be reused. I also do not know how to erase the contour-fill although, based on the generated PNG files, it does not, for unknown reasons , appear to be necessary. From some postings, it seems that I have to employ collections attributes, but I have not been able to find documentation or examples that illustrate this.
My system: * matplotlib.__version__: '0.91.2' * sys.version: '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]' Thanks, -- jv
''' PURPOSE Discover a procedure for eliminating the need to redraw each map projection from scratch each there is new data to be plotted. Redrawing each map is time-consuming! AUTHOR [EMAIL PROTECTED] ''' import pylab from matplotlib.toolkits.basemap import Basemap import numpy import os parameters = dict(projection='merc', llcrnrlon=-180,urcrnrlon=180, llcrnrlat=-80,urcrnrlat=85, lon_0=100,lat_ts=20, resolution='c') map = Basemap(**parameters) map.drawcoastlines() map.drawmapboundary() map.drawmeridians(pylab.arange(0,360,30)) map.drawparallels(pylab.arange(-90,90,30)) parameters = dict(num=1, figsize=(8, 8), dpi=80, facecolor='w', edgecolor='k', frameon=False) figure = pylab.figure(**parameters) pylab.title('Figure-reuse Trial') def render(data): timestamp, longitudes, latitudes, values = data['timestamp'], data['longitudes'], data['latitudes'], data['values'] longitudes, latitudes = pylab.meshgrid(longitudes, latitudes) pylab.figure(num=1) # set current figure parameters = dict(alpha=1, color='white', fontsize=12, fontweight='heavy', horizontalalignment='left', verticalalignment='center', transform=pylab.gca().transAxes) pylab.text(0.01,0.98, timestamp, **parameters) x, y = map(longitudes, latitudes) map.contourf(x, y, values) filename = os.extsep.join(('Reuse-trial',str(data['timestamp'])[:10],'png')) pylab.savefig(filename) ##pylab.show() #~ _restore_(figure) TBD: how to erase current label and contour fill colors although the latter erasure surprisingly does not seem to be required ! def timeline(): ''' a generator for fabricated, planet-wide, data for testing purposes ''' data = dict() delta_x, delta_y = 1.0, 0.5 data['longitudes'] = numpy.arange(-180.0, 180.0+delta_x, delta_x) data['latitudes'] = numpy.arange(-90.0, 90.0+delta_y, delta_y) computations = dict(yesterday=horizontal(data['longitudes'], data['latitudes']), today=vertical(data['longitudes'], data['latitudes'])) for timestamp,values in computations.items(): data['timestamp'] = timestamp data['values'] = values yield data def horizontal(longitudes,latitudes): data = numpy.empty(shape=(longitudes.size, latitudes.size), dtype=float, order='C') for index,longitude in enumerate(longitudes): data[index] = longitude return data def vertical(longitudes,latitudes): data = numpy.empty(shape=(longitudes.size, latitudes.size), dtype=float, order='C') for index,latitude in enumerate(latitudes): data[:,index] = latitude return data for data in timeline(): render(data)
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users