Pierre GM wrote:
Pierre: The reason I did it that way was so that the basemap instance could be created independent of any axes instances. For instance, you can create a basemap instance before an axes instance is created, or you read in a basemap instance from a pickle. If a axes instance is associated with a Basemap instance, you can't save it in a pickle.
I understand that, I use pickled basemaps all the time. It's a great feature, by the way, thanks a lot.
If I understand you correctly, you are suggesting that when the basemap instance is created, the "ax" attribute be set to plt.gca() if no axes instance is passed in through the kwarg, instead of just setting it to None.
In that case, an axes instance will be created and assigned to the Basemap instance if one doesn't already exist.
That's the gist of it, yes. My point is that as soon something is drawn, the basemap should be linked to an Axes instance. The link could be overwritten later.
I guess I don't see any compelling reason for that, since you can always assign an axes instance to the Basemap instance later (via "map.ax = plt.gca()".
I'd rather have this done explicitly by the user, than have it happen automatically, with potentially surprising results.
Well, talking about surprising results, the experience I was relating in the original message: I load a basemap from a pickle, plot some contours on it (therefore, a new Axes is created), add a colorbar (a second Axes is created) and then draw a mapscale. I expect the mapscale to be drawn on the axes associated with the basemap, because I'm using one of the basemap's methods to plot the mapscale. With the current implementation, the scale gets drawn on the colorbar.
So yes, I could explicitly link the basemap to the first Axes myself. I still think my suggestion would be far less confusing, but I won't lose sleep over it. In any case, I think the snippet I put in the latest message could simplify the code (just drop the line setting self.ax to ax)...
Pierre: Doing what you suggest (having Basemap.__init__ automatically set self.ax to the current axes) will break pickling, so I can't do that. I think the next best thing is just to set it manually. I know the colorbar behavior is annoying, but I think it's just something you have to live with if you use the pylab interface.
On Jun 23, 2009, at 8:27 AM, Jeff Whitaker wrote:
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-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg