def plot_enso_background(self, ensoindices=None, lag=0, **optinfo): """ Plots colored stripes in the background of plot to represent ENSO phases. Parameters ---------- ensophases: {array-like}, optional Array of ENSO indices (``+1`` for El Niño, ``0`` for Neutral and ``-1`` for La Niña episodes). If None, the ENSO indices of the underlying series are used instead. """ if ensoindices is None: series = self._series if series is None or not hasattr(series, 'ensoindices') or \ series.ensoindices is None: raise ValueError("Undefined ENSO indices!") ensoindices = series.ensoindices if self.xdata is None: errmsg = "Unable to retrieve the dates of the current plot!" raise ValueError(errmsg) # dates = self.xdata clust_indices = Cluster(ensoindices.filled(0), 0) _dates = np.empty(len(dates) + 1, int) _dates[:-1] = dates _dates[-1] = dates[-2] episodes = dict([(k, zip(_dates[v[:, 0]], _dates[v[:, 1]])) for (k, v) in clust_indices.grouped_limits().items()]) # colors = ENSOcolors['polygons'] for (key, idx) in {'C': -1, 'N': 0, 'W': +1}.iteritems(): colors[idx] = colors[key] # trans = blended_transform_factory(self.transData, self.transAxes) for (k, lim) in episodes.iteritems(): _bbc = BrokenBarHCollection( [(x + lag, y - x) for (x, y) in lim], (0, 1), facecolors=colors[k], edgecolors=colors[k], ) _bbc.set_alpha(0.2) _bbc.set_transform(trans) self.add_collection(_bbc)
def plot_enso_background(self, ensoindices=None, lag=0, **optinfo): """ Plots colored stripes in the background of plot to represent ENSO phases. Parameters ---------- ensophases: {array-like}, optional Array of ENSO indices (``+1`` for El Niño, ``0`` for Neutral and ``-1`` for La Niña episodes). If None, the ENSO indices of the underlying series are used instead. """ if ensoindices is None: series = self._series if series is None or not hasattr(series, 'ensoindices') or \ series.ensoindices is None: raise ValueError("Undefined ENSO indices!") ensoindices = series.ensoindices if self.xdata is None: errmsg = "Unable to retrieve the dates of the current plot!" raise ValueError(errmsg) # dates = self.xdata clust_indices = Cluster(ensoindices.filled(0), 0) _dates = np.empty(len(dates) + 1, int) _dates[:-1] = dates _dates[-1] = dates[-2] episodes = dict([(k, zip(_dates[v[:, 0]], _dates[v[:, 1]])) for (k, v) in clust_indices.grouped_limits().items()]) # colors = ENSOcolors['polygons'] for (key, idx) in {'C':-1, 'N':0, 'W':+1}.iteritems(): colors[idx] = colors[key] # trans = blended_transform_factory(self.transData, self.transAxes) for (k, lim) in episodes.iteritems(): _bbc = BrokenBarHCollection([(x + lag, y - x) for (x, y) in lim], (0, 1), facecolors=colors[k], edgecolors=colors[k],) _bbc.set_alpha(0.2) _bbc.set_transform(trans) self.add_collection(_bbc)