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 ?
Thanks a lot in advance for any explanation:
[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)
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:
ax = plt.gca()
import matplotlib.pyplot as plt
ax = plt.gca()
self.ax = ax