I reuse a Basemap instance to reduce processing time. What I do is
basically:

1. Remember all items I added to the map
2. Remove all items I don't want to keep


I use a list for every category of items (contoursets, clabels, texts,
...), as the way to remove them is slightly different.

Then I remove them from the map axes:

for contourset in contoursets_to_remove:
  for coll in contourset.collections:
    if coll in map_axes.collections:
      map_axes.collections.remove(coll)


for label in clabels_to_remove:
  if label in map_axes.artists:
   map_axes.artists.remove(label)


for txt in texts_to_remove:
  if txt in map_axes.texts:
   map_axes.texts.remove(txt)



Works well for me, but I would not be suprised if there's an more
matplotlib-like method...

While writing these lines, I start to wonder if it wouldn't be more
elegant to remember the items you want to keep (coastlines,...), then do
map_axes.cla() an then add your items to the map axes again?! For my
application, this seems to be the better way, as I'm deleting more
elements than reusing elements.

Shouldn't be too hard to rewrite my code, maybe I can tell you if it
works in a few days.



Cheers
Simon





Jesper Larsen schrieb:
> On Tuesday 08 May 2007 20:55, Jeff Whitaker wrote:
>> Jesper:  You might consider just deleting the figure elements that you
>> don't want to re-use (instead of figuring out everything you do want to
>> re-use).
> 
> I have an axes instance on which I have plotted my map decorations 
> (coastlines, meridians and so on). I would like to reuse that axes. On the 
> same axes* I would like to make filled contour plot and potentially a quiver 
> plot. These should be discarded after saving the plot to a file.
> 
> I know I have to discard part of the "collection" variable in the axes 
> instance. But it seems like other things are changed as well. Is it safe to 
> ignore these and simply do something like this:
> 
> nsave = len(ax.collections)
> 
> ...do and save plot...
> 
> ax.collections = ax.collections[0:nsave]
> 
> or would you recommend doing something else?
> 
> Regards,
> Jesper
> 
> *) I have tried to make an extra axes for the contour plot itself but it 
> seems 
> like matplotlib does not create an extra axes when it is the same size as an 
> existing axes.
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to