Exemple #1
0
    def result(self, boxkwargs=None, figsize=(12, 10), maxpoints=1000):
        """

        :return:
        """

        if boxkwargs is None:
            boxkwargs = {}

        filtered = random.sample(list(self.df.index), maxpoints)
        sampled_df = self.df.ix[filtered]

        fig = mpl.figure.Figure(figsize=figsize, tight_layout=True)
        canvas = mbb.FigureCanvasAgg(fig)
        grid = gs.GridSpec(4, 3, width_ratios=[4, 4, 1], height_ratios=[2, 1, 2, 1])

        axm = fig.add_subplot(grid[0], label="axm")
        axmd = fig.add_subplot(grid[1], label="axmd")
        axtm = fig.add_subplot(grid[3], label="axtm", frameon=False)
        axtmd = fig.add_subplot(grid[4], label="axtmd", frameon=False)
        axs = fig.add_subplot(grid[6], label="axs")
        axsd = fig.add_subplot(grid[7], label="axsd")
        axts = fig.add_subplot(grid[9], label="axts", frameon=False)
        axtsd = fig.add_subplot(grid[10], label="axtsd", frameon=False)

        jp.boxplot("Group", "Mean", sampled_df, axes=axm, legend="Group", **boxkwargs)
        jp.boxplot("Group", "Mean Delta", sampled_df, axes=axmd, legend="Group", **boxkwargs)
        jp.boxplot("Group", "Sigma", sampled_df, axes=axs, legend="Group", **boxkwargs)
        jp.boxplot("Group", "Sigma Delta", sampled_df, axes=axsd, legend="Group", **boxkwargs)

        jp.components.datatable("Mean", self.df, axtm, by="Group", probs="bayes")
        jp.components.datatable("Mean Delta", self.df, axtmd, by="Group", probs="bayes")
        jp.components.datatable("Sigma", self.df, axts, by="Group", probs="bayes")
        jp.components.datatable("Sigma Delta", self.df, axtsd, by="Group", probs="bayes")

        for ax in axm, axmd, axtm, axtmd, axs, axsd, axts, axtsd:
            if not ax:
                continue

            ax.tick_params(top="off")
            ax.tick_params(bottom="off")
            ax.tick_params(right="off")
            ax.tick_params(left="off")

        fig.suptitle("")
        return canvas.figure
Exemple #2
0
    def result(self, boxkwargs=None, figsize=(12, 10), maxpoints=1000):
        """

        :return:
        """

        if boxkwargs is None:
            boxkwargs = {}

        filtered = random.sample(list(self.df.index), maxpoints)
        sampled_df = self.df.ix[filtered]

        fig = mpl.figure.Figure(figsize=figsize, tight_layout=True)
        canvas = mbb.FigureCanvasAgg(fig)
        grid = gs.GridSpec(4,
                           3,
                           width_ratios=[4, 4, 1],
                           height_ratios=[2, 1, 2, 1])

        axm = fig.add_subplot(grid[0], label='axm')
        axmd = fig.add_subplot(grid[1], label='axmd')
        axtm = fig.add_subplot(
            grid[3],
            label='axtm',
            frameon=False,
        )
        axtmd = fig.add_subplot(
            grid[4],
            label='axtmd',
            frameon=False,
        )
        axs = fig.add_subplot(grid[6], label='axs')
        axsd = fig.add_subplot(grid[7], label='axsd')
        axts = fig.add_subplot(
            grid[9],
            label='axts',
            frameon=False,
        )
        axtsd = fig.add_subplot(
            grid[10],
            label='axtsd',
            frameon=False,
        )

        jp.boxplot('Group',
                   'Mean',
                   sampled_df,
                   axes=axm,
                   legend='Group',
                   **boxkwargs)
        jp.boxplot('Group',
                   'Mean Delta',
                   sampled_df,
                   axes=axmd,
                   legend='Group',
                   **boxkwargs)
        jp.boxplot('Group',
                   'Sigma',
                   sampled_df,
                   axes=axs,
                   legend='Group',
                   **boxkwargs)
        jp.boxplot('Group',
                   'Sigma Delta',
                   sampled_df,
                   axes=axsd,
                   legend='Group',
                   **boxkwargs)

        jp.components.datatable('Mean',
                                self.df,
                                axtm,
                                by='Group',
                                probs='bayes')
        jp.components.datatable('Mean Delta',
                                self.df,
                                axtmd,
                                by='Group',
                                probs='bayes')
        jp.components.datatable('Sigma',
                                self.df,
                                axts,
                                by='Group',
                                probs='bayes')
        jp.components.datatable('Sigma Delta',
                                self.df,
                                axtsd,
                                by='Group',
                                probs='bayes')

        for ax in axm, axmd, axtm, axtmd, axs, axsd, axts, axtsd:
            if not ax:
                continue

            ax.tick_params(top="off")
            ax.tick_params(bottom="off")
            ax.tick_params(right="off")
            ax.tick_params(left="off")

        fig.suptitle('')
        return canvas.figure
Exemple #3
0
def varchart(x: list,
             y: str,
             data: pd.DataFrame,
             legend=None,
             cumprob: bool=False,
             fig=None,
             **kwargs):
    """
    varchart function
    :param x: list of strings
    :param y: str
    :param data: pd.Dataframe, source of data
    :param legend: str, color code by this column
    :param cumprob, turn on or off the cumprob plots
    :param table: turn on or off the datatable
    **kwargs: other parameters to pass into the jumpy.boxplot function
    """

    local_data = data.copy()
    local_data = local_data.reset_index()

    strx = str(x)
    strl = None

    # ensure blox plot x axis is a string and y data is all float
    for var in x:
        local_data[var] = local_data[var].astype('str')

    local_data[y] = local_data[y].astype('float').dropna()

    # join all x's into a single column
    for i, part in enumerate(x):
        if i == 0:
            local_data[strx] = local_data[part].map(str)
        else:
            local_data[strx] += local_data[part].map(str)

        if i < len(x) - 1:
            local_data[strx] += ', '

    # create a new legend column if legend is an array
    if legend and isinstance(legend, str):
        strl = legend
    elif str(legend) == strx:
        strl = strx
    elif legend:
        # make a column that has the concatenated legend label
        strl = str(legend)
        for i, part in enumerate(legend):
            if i == 0:
                local_data[strl] = local_data[part].map(str)
            else:
                local_data[strl] += local_data[part].map(str)

            if i < len(legend) - 1:
                local_data[strl] += ', '

    if fig:
        fig = boxplot(x=strx, y=y, data=local_data, orderby=strx,
                      legend=strl, cumprob=cumprob, fig=fig, **kwargs)
    else:
        fig = boxplot(x=strx, y=y, data=local_data, orderby=strx,
                      legend=strl, cumprob=cumprob, **kwargs)

    axm, axc, axl, axt = components.get_axes(fig, clear=False)

    yvals = axm.get_ylim()
    colors = ['w', 'b', 'r', 'g', 'c']

    # this array holds all the multple numbers for when to draw a line.
    # % operator is called on each of these
    nummods = [len(set(local_data[x[k]])) for k in range(len(x)) if k >= 1]
    for j, k in enumerate(reversed(range(len(nummods)))):
        if j == 0:
            nummods[k] = nummods[k]
        else:
            nummods[k] *= nummods[k-1]

    # generate every possible permutation of the incoming arrays
    for i, combo in enumerate(sorted(set(local_data[strx])), start=1):
        # draw in vertical lines
        for j, mod in enumerate(reversed(nummods)):
            if not i % mod:
                axm.vlines(i-.5, *yvals, color='{}'.format(colors[j+1]),
                           alpha=.5)

    axm.set_ylim(*yvals)
    fig.suptitle('')

    return fig
Exemple #4
0
def varchart(x: list,
             y: str,
             data: pd.DataFrame,
             legend=None,
             cumprob: bool = False,
             fig=None,
             **kwargs):
    """
    varchart function
    :param x: list of strings
    :param y: str
    :param data: pd.Dataframe, source of data
    :param legend: str, color code by this column
    :param cumprob, turn on or off the cumprob plots
    :param table: turn on or off the datatable
    **kwargs: other parameters to pass into the jumpy.boxplot function
    """

    local_data = data.copy()
    local_data = local_data.reset_index()

    strx = str(x)
    strl = None

    # ensure blox plot x axis is a string and y data is all float
    for var in x:
        local_data[var] = local_data[var].astype('str')

    local_data[y] = local_data[y].astype('float').dropna()

    # join all x's into a single column
    for i, part in enumerate(x):
        if i == 0:
            local_data[strx] = local_data[part].map(str)
        else:
            local_data[strx] += local_data[part].map(str)

        if i < len(x) - 1:
            local_data[strx] += ', '

    # create a new legend column if legend is an array
    if legend and isinstance(legend, str):
        strl = legend
    elif str(legend) == strx:
        strl = strx
    elif legend:
        # make a column that has the concatenated legend label
        strl = str(legend)
        for i, part in enumerate(legend):
            if i == 0:
                local_data[strl] = local_data[part].map(str)
            else:
                local_data[strl] += local_data[part].map(str)

            if i < len(legend) - 1:
                local_data[strl] += ', '

    if fig:
        fig = boxplot(x=strx,
                      y=y,
                      data=local_data,
                      orderby=strx,
                      legend=strl,
                      cumprob=cumprob,
                      fig=fig,
                      **kwargs)
    else:
        fig = boxplot(x=strx,
                      y=y,
                      data=local_data,
                      orderby=strx,
                      legend=strl,
                      cumprob=cumprob,
                      **kwargs)

    axm, axc, axl, axt = components.get_axes(fig, clear=False)

    yvals = axm.get_ylim()
    colors = ['w', 'b', 'r', 'g', 'c']

    # this array holds all the multple numbers for when to draw a line.
    # % operator is called on each of these
    nummods = [len(set(local_data[x[k]])) for k in range(len(x)) if k >= 1]
    for j, k in enumerate(reversed(range(len(nummods)))):
        if j == 0:
            nummods[k] = nummods[k]
        else:
            nummods[k] *= nummods[k - 1]

    # generate every possible permutation of the incoming arrays
    for i, combo in enumerate(sorted(set(local_data[strx])), start=1):
        # draw in vertical lines
        for j, mod in enumerate(reversed(nummods)):
            if not i % mod:
                axm.vlines(i - .5,
                           *yvals,
                           color='{}'.format(colors[j + 1]),
                           alpha=.5)

    axm.set_ylim(*yvals)
    fig.suptitle('')

    return fig