Pierre GM wrote:
> All (and Jeff W. in particular),
>
> It's the time of the year where I have to draw maps in batch. I wrote  
> a script to process some data recorded at various stations,  
> interpolate the data on a grid, draw the corresponding contours on a  
> basemap, add a colorbar, and end with adding some extra information on  
> the map (scale, stations positions...).
>
> Nothing too fancy, but I ran into a problem with the last few steps.  
> As I do not give an explicit 'ax' parameter to any of the basemap  
> related methods (.contourf, .plot, .drawmapscale...), I have to rely  
> on the defaults: use self.ax if it is not None, gca() otherwise.  
> However, drawing a colorbar in midprocess switches the focus to the  
> colorbar, and the extra information I was talking about gets plotted  
> on the colorbar.
>
> Which brings me to the famous question: is it a bug or a feature ? Is  
> there any rational in *not* setting the 'ax' attribute to gca() when  
> sit hasn't been set yet and no 'ax' parameter has been specifically  
> given as input of a method ?
>   

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.  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.  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. 

-Jeff
> Thanks a lot in advance for any explanation:
> P.
>
>
> [As a workaround, I modified my local sources by adding a ._check_ax  
> method as below, and used :
> ax = ax or self._check_ax(ax)
> or
> ax = kwargs.pop('ax', None) or self._check_ax()
> depending on the context
>
>      def _check_ax(self, ax=None):
>          """
>      Returns the axis on which to draw.
>      By default, returns self.ax. If this latter is None, set it to  
> gca().
>          """
>          #
>          if ax is None:
>              if self.ax is None:
>                  try:
>                      ax = plt.gca()
>                  except:
>                      import matplotlib.pyplot as plt
>                      ax = plt.gca()
>                  self.ax = ax
>              return self.ax
>          return ax
>
> ------------------------------------------------------------------------------
> Are you an open source citizen? Join us for the Open Source Bridge conference!
> Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
> Need another reason to go? 24-hour hacker lounge. Register today!
> http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>   


------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to