def plot_jma(num=None, fill=True, full_year=False, fill_neutral=False):
    if num is None:
        fig = csfigure(series=JMA)
    else:
        fig = csfigure(num=num, series=JMA)
    fig.clear()
    fsp = fig.add_csplot(111)
    fill_colors = ENSOcolors['fill']
    polygon_colors = ENSOcolors['polygons']
    marker_colors = ENSOcolors['markers']
    line_colors = ENSOcolors['lines']
    #
    enso_indices = JMA.set_indices(full_year=full_year)
    xxthcentury = (JMA.years >= 1900)
    imask = enso_indices
    cold = JMA[((enso_indices == -1) & xxthcentury).filled(False)]
    neutral = JMA[((enso_indices == 0) & xxthcentury).filled(False)]
    warm = JMA[((enso_indices == +1) & xxthcentury).filled(False)]
    #
    _JMA = JMA[xxthcentury]
    #
    xdata = enso_indices._dates.tovalue()
    #
    fsp.tsplot(_JMA)
    if fill:
        cold = _JMA.view(type(_JMA))
        cold.unshare_mask()
        cold.__setmask__((enso_indices != -1), copy=True)
        fsp.fill(xdata, cold._series.filled(_JMA.thresholds[0]),
                 ec=fill_colors['C'], fc=fill_colors['C'])
        warm = _JMA.view(type(_JMA))
        warm.unshare_mask()
        warm.__setmask__((enso_indices != 1), copy=True)
        fsp.fill(xdata, warm._series.filled(JMA.thresholds[-1]),
                 ec=fill_colors['W'], fc=fill_colors['W'])
        if fill_neutral:
            neutral = _JMA.view(type(_JMA))
            neutral.unshare_mask()
            neutral.__setmask__((enso_indices != 0).filled(True), copy=True)
            fsp.fill(xdata, neutral._series.filled(0),
                     ec=fill_colors['N'], fc=fill_colors['N'])
    else:
        fsp.tsplot(cold, marker='o', c=marker_colors['C'], ls='')
        fsp.tsplot(neutral, marker='o', c=marker_colors['N'], ls='')
        fsp.tsplot(warm, marker='o', c=marker_colors['W'], ls='')
    #
    fsp.axhline(0, ls='-', c='k')
    fsp.axhline(_JMA.thresholds[-1], ls='-.', c=line_colors['W'])
    fsp.axhline(_JMA.thresholds[0], ls='-.', c=line_colors['C'])
    fsp.format_dateaxis()
    fsp.set_datelimits(end_date='2010')
    #
    fsp.set_ylabel("5-m Averaged SST Anomalies (oC)", fontweight='bold')
    fsp.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(0.5))
    fsp.set_xlabel("Years", fontweight='bold')
    cpl.show()
    return fig
Exemplo n.º 2
0
fig = cpl.hydrograph(rainfall, flowdata, figsize=(12,6))

"""
The handle of the hyetograph subplot can be accessed through the :attr:`hyeto` 
attribute of the figure, and the handle of hydrograph through the :attr:`hydro`
attribute.

We can set the labels of the y-axis:
"""
fig.hyeto.set_ylabel("Rainfall (mm)", fontweight='bold')
fig.hydro.set_ylabel("Flows (cfs)", fontweight='bold')
fig.suptitle("Hydrograph for the North Oconee River at Athens, GA",
             fontweight="bold", fontsize=12)
fig.savefig("athens_hydrograph.png")

"""
As the hydrograph is a subclass of :class:`~scikits.timeseries.lib.plotlib.TimeSeriesFigure`,
the ticks on the x axis of each subplot are automatically adjusted with the level
of zoom.
Moreover, as the two subplots share the same x-axis, any modification on one
subplot is reflected on the other.
As an example, let's focus on the year 2005.

"""

fig.hyeto.set_datelimits('2005-01-01', '2005-12-31')
fig.savefig("athens_hydrograph_zoomed.png")
cpl.show()

def plot_jma_vs_oni_comparison(freq='M'):
    """
    Plots the comparison of ONI vs JMAI ENSO indices at the given frequency.
    """
    # Check that we have a valid frequency
    freq = climpy.check_freq(freq)
    # Get the ENSO indices: annual for 12 months period, monthly on a monthly basis
    JMAi = JMA.indices(full_year=False, reference_season='NDJ', minimum_size=6)
    ONIi = ONI.indices(full_year=False, reference_season=None, minimum_size=5)
    # Convert to the new frequency
    if freq != climpy._c.FR_MTH:
        JMAi = np.round_(JMAi.convert(freq, func=ma.mean))
        ONIi = np.round_(ONIi.convert(freq, func=ma.mean))
    # Convert the indices to a Nx12 series (N the nb of years)
    JMAi = JMAi.convert('A')
    ONIi = ONIi.convert('A')
    #
    JMAi = JMAi[JMAi.year >= 1900]
    ONIi = ONIi[ONIi.year >= 1900]
    #
    j_colors = get_colormatrix(JMAi)
    o_colors = get_colormatrix(ONIi)
    #
    fig = cpl.figure(num=1, figsize=(13, 5))
    fig.clear()
    fsp = fig.add_axes([0.05, 0.1, 0.85, 0.85])
    (nrows, ncols) = j_colors.shape
    edgecolors = 'none'
    #
    j_vert = np.array([[((i, j + 1), (i, j), (i + 1, j)) for i in range(ncols)]
                          for j in range(nrows)]).reshape(-1, 3, 2)
    j_coll = matplotlib.collections.PolyCollection(j_vert,
                                                  facecolors=j_colors.ravel(),
                                                  edgecolors=edgecolors)
    fsp.add_collection(j_coll)
    #............................................
    o_vert = np.array([[((i, j + 1), (i + 1, j + 1), (i + 1, j)) for i in range(ncols)]
                          for j in range(nrows)]).reshape(-1, 3, 2)
    o_coll = matplotlib.collections.PolyCollection(o_vert,
                                                  facecolors=o_colors.ravel(),
                                                  edgecolors=edgecolors)
    fsp.add_collection(o_coll)
    #............................................
    xy_vert = [((i, 0), (i, nrows)) for i in range(0, ncols, 12)]
    xy_vert += [((0, j), (ncols, j)) for j in range(nrows)]
    xy_coll = matplotlib.collections.LineCollection(xy_vert,
                                                    colors='k')
    fsp.add_collection(xy_coll)
    #............................................
    fsp.xaxis.set_major_locator(cpl.MultipleLocator(12))
    fsp.set_xticks(np.arange(0, ncols, 12) + 6)
    fsp.set_xticklabels(["%02i" % i for i in range(12)])
    fsp.set_xlim(0, ncols)
    #............................................
    fsp.set_yticks(np.arange(0, nrows) + 0.5)
    fsp.set_yticklabels(["%i" % (i * 10 + 1900) for i in range(nrows + 1)])
    fsp.set_ylim(0, nrows)
    fsp.set_ylim(fsp.get_ylim()[::-1])
    add_plot_legend(fig, lableft='JMA', labright='ONI')
    cpl.show()
    return fig
Exemplo n.º 4
0
"""

fig = cpl.hydrograph(rainfall, flowdata, figsize=(12, 6))
"""
The handle of the hyetograph subplot can be accessed through the :attr:`hyeto` 
attribute of the figure, and the handle of hydrograph through the :attr:`hydro`
attribute.

We can set the labels of the y-axis:
"""
fig.hyeto.set_ylabel("Rainfall (mm)", fontweight='bold')
fig.hydro.set_ylabel("Flows (cfs)", fontweight='bold')
fig.suptitle("Hydrograph for the North Oconee River at Athens, GA",
             fontweight="bold",
             fontsize=12)
fig.savefig("athens_hydrograph.png")
"""
As the hydrograph is a subclass of :class:`~scikits.timeseries.lib.plotlib.TimeSeriesFigure`,
the ticks on the x axis of each subplot are automatically adjusted with the level
of zoom.
Moreover, as the two subplots share the same x-axis, any modification on one
subplot is reflected on the other.
As an example, let's focus on the year 2005.

"""

fig.hyeto.set_datelimits('2005-01-01', '2005-12-31')
fig.savefig("athens_hydrograph_zoomed.png")
cpl.show()