コード例 #1
0
ファイル: std.py プロジェクト: roualdes/bplot
def std_h(
    x,
    y,
    z=1.96,
    z_inner=0.675,
    color="tab:blue",
    label="",
    style="o",
    alpha=1.0,
    ax=None,
):
    """Draw horizontal standard deviation intervals.


    Parameters
    ----------
    x : {numpy.array, pandas.core.series.Series}
        The vector of data for which the standard deviation interval is sought.

    y : int
        The location along the y-axis at which the vertical interval is placed.

    z_inner : float, 0.675 by default
        The number of standard deviations from the mean for the inner bound.

    color : string, 'tab:blue' by default
        The color of the rug.

    label : string, '' (empty) by default
        The label within a potential legend.

    style : string, 'o' by default
        The shape of the mean point.

    alpha : float, 1.0 by default
        The transparency of the color.  Values between 0 (transparent) and 1 (opague) are allowed.

    ax : matplotlib.pyplot.Axes, None by default
        The axis onto which the box is drawn.  If left as None,
        matplotlib.pyplot.gca() is called to get the current `Axes`.


    Returns
    -------
    out : matplotlib.pyplot.Axes
        The `Axes` onto which the box was drawn.
    """

    x, _, ax = check_data(x, None, ax)

    xbar, std = np.mean(x), np.std(x)

    lw_mid, uw_mid = xbar - z_inner * std, xbar + z_inner * std
    lw, uw = xbar - z * std, xbar + z * std

    line_h(y, lw, uw, color=color, alpha=alpha)
    line_h(y, lw_mid, uw_mid, lw=4, color=color, alpha=alpha)

    out = point(xbar,
                y,
                color=color,
                label=label,
                size=2,
                style=style,
                alpha=alpha)
    return out
コード例 #2
0
ファイル: box.py プロジェクト: roualdes/bplot
def box_h(x,
          y,
          color="tab:blue",
          label="",
          style="o",
          alpha=1.0,
          ax=None,
          **kws):
    """Draw horizontal box plot.


    Parameters
    ----------
    x : {numpy.array, pandas.core.series.Series}
        The vector of data for which the standard five number summary
        is sought.

    y : scalar
        The location along the x-axis at which the vertical box is placed.

    color : string, 'tab:blue' by default
        The color of the box.

    label : string, '' (empty) by default
        The label within a potential legend.

    style : string, 'o' by default
        The shape of the median within the box.

    alpha : float, 1.0 by default
        The transparency of the color.  Values between 0 (transparent) and 1 (opague) are allowed.

    ax : matplotlib.pyplot.Axes, None by default
        The axis onto which the box is drawn.  If left as None,
        matplotlib.pyplot.gca() is called to get the current `Axes`.


    Returns
    -------

    out : matplotlib.pyplot.Axes
        The `Axes` onto which the box was drawn.
    """

    x, _, ax = check_data(x, None, ax)

    q1, q2, q3, lw, uw = _bx(x)

    line_h(y, lw, uw, size=2, color=color, alpha=alpha)
    line_h(y, q1, q3, size=5, color=color, alpha=alpha)

    u_outs = x[np.where(x > uw)]
    l_outs = x[np.where(x < lw)]

    point(u_outs,
          np.repeat(y, u_outs.size),
          style="*",
          color=color,
          alpha=alpha)
    point(l_outs,
          np.repeat(y, l_outs.size),
          style="*",
          color=color,
          alpha=alpha)

    out = point(q2,
                y,
                size=2,
                style=style,
                color=color,
                label=label,
                alpha=alpha)
    return out
コード例 #3
0
ファイル: percentile.py プロジェクト: roualdes/bplot
def percentile_h(x,
                 y,
                 outer=0.8,
                 inner=0.5,
                 color="tab:blue",
                 label="",
                 style="o",
                 alpha=1,
                 ax=None,
                 **kws):
    """Draw horizontal percentile interval.


    Parameters
    ----------
    x : {numpy.array, pandas.core.series.Series}
        The vector of data for which the `outer` percentile interval is sought.

    y : int
        The location along the y-axis at which the interval is placed.

    outer : float, 0.8 by default
        The outer interval percentage.

    inner : float, 0.5 by default
        The inner interval percentage.

    color : string, 'tab:blue' by default
        The color of the box.

    label : string, '' (empty) by default
        The label within a potential legend.

    style : string, 'o' by default
        The shape of the median within the box.

    alpha : float, 1.0 by default
        The transparency of the color.  Values between 0 (transparent) and 1 (opague) are allowed.

    ax : matplotlib.pyplot.Axes, None by default
        The axis onto which the box is drawn.  If left as None,
        matplotlib.pyplot.gca() is called to get the current `Axes`.


    Returns
    -------

    out : matplotlib.pyplot.Axes
        The `Axes` onto which the box was drawn.
    """

    x, _, ax = check_data(x, None, ax)

    alpha_l, alpha_lm = (1 - outer) / 2, (1 - inner) / 2
    l, lm, m, um, u = alpha_l, alpha_lm, 0.5, 1 - alpha_lm, 1 - alpha_l
    q_l, q_lm, q_m, q_um, q_u = np.percentile(
        x,
        np.array([l, lm, m, um, u]) * 100)

    line_h(y, q_l, q_u, size=2, color=color, alpha=alpha)
    line_h(y, q_lm, q_um, size=5, color=color, alpha=alpha)

    out = point(q_m,
                y,
                size=2,
                style=style,
                color=color,
                label=label,
                alpha=alpha)
    return out
コード例 #4
0
ファイル: lag.py プロジェクト: roualdes/bplot
def lag(x,
        lag=1,
        color="tab:blue",
        label="",
        style="o",
        size=1.0,
        alpha=1.0,
        ax=None,
        **kws):
    """Draw lag plot.

    Parameters
    ----------
    x : {numpy.array, pandas.core.series.Series}
        The location along the x-axis at which the lags are drawn.

    lag : float, 1 by default
        The lag of the plot.

    color : string, 'tab:blue' by default
        The color of the box.

    label : string, '' (empty) by default
        The label within a potential legend.

    size : int, 1 by default
        The size of the points to draw.  In matplotlib terms, this is equivalent to mpl.rcParam['lines.markersize'] = 6**(size + 1).

    style : string, 'o' by default
        The shape of the median within the box.

    alpha : float, 1.0 by default
        The transparency of the color.  Values between 0 (transparent) and 1 (opague) are allowed.

    ax : matplotlib.pyplot.Axes, None by default
        The axis onto which the box is drawn.  If left as None,
        matplotlib.pyplot.gca() is called to get the current `Axes`.


    Returns
    -------

    out : matplotlib.pyplot.Axes
        The `Axes` onto which the box was drawn.
    """

    x, _, ax = check_data(x, None, ax)

    y1 = x[:-lag]
    y2 = x[lag:]

    out = point(y1,
                y2,
                color=color,
                label=label,
                style=style,
                size=size,
                alpha=alpha,
                ax=ax,
                **kws)
    return out
コード例 #5
0
ファイル: mad.py プロジェクト: roualdes/bplot
def mad(
    x,
    y,
    z=1.96,
    z_inner=0.675,
    color="tab:blue",
    label="",
    style="o",
    alpha=1.0,
    ax=None,
):
    """Draw vertical median absolute deviation intervals.


    Parameters
    ----------
    x : int
        The location along the x-axis at which the vertical interval is placed.

    y : {numpy.array, pandas.core.series.Series}
        The vector of data for which the standard deviation is sought.

    z : float, 1.96 by default
        The number of standard deviations from the mean for the outer bound.

    z_inner : float, 0.675 by default
        The number of standard deviations from the mean for the inner bound.

    color : string, 'tab:blue' by default
        The color of the rug.

    label : string, '' (empty) by default
        The label within a potential legend.

    style : string, 'o' by default
        The shape of the mean point.

    alpha : float, 1.0 by default
        The transparency of the color.  Values between 0 (transparent) and 1 (opague) are allowed.

    ax : matplotlib.pyplot.Axes, None by default
        The axis onto which the box is drawn.  If left as None,
        matplotlib.pyplot.gca() is called to get the current `Axes`.


    Returns
    -------
    out : matplotlib.pyplot.Axes
        The `Axes` onto which the box was drawn.
    """

    _, y, ax = check_data(None, y, ax)

    med, mad = np.median(y), mad_std(y) / norm.ppf(0.75)

    lw_mid, uw_mid = med - z_inner * mad, med + z_inner * mad
    lw, uw = med - z * mad, med + z * mad

    line_v(x, lw, uw, size=2, color=color, alpha=alpha)
    line_v(x, lw_mid, uw_mid, size=5, color=color, alpha=alpha)

    out = point(x,
                med,
                size=2,
                style=style,
                color=color,
                label=label,
                alpha=alpha)
    return out