bokeh.transform.cumsum

Here are the examples of the python api bokeh.transform.cumsum taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

3 View Source File : test_transform.py
License : MIT License
Project Creator : rthorst

    def test_basic(object):
        s = bt.cumsum("foo")
        assert isinstance(s, dict)
        assert list(s.keys()) == ["expr"]
        assert isinstance(s['expr'], CumSum)
        assert s['expr'].field == 'foo'
        assert s['expr'].include_zero == False

    def test_include_zero(object):

3 View Source File : test_transform.py
License : MIT License
Project Creator : rthorst

    def test_include_zero(object):
        s = bt.cumsum("foo", include_zero=True)
        assert isinstance(s, dict)
        assert list(s.keys()) == ["expr"]
        assert isinstance(s['expr'], CumSum)
        assert s['expr'].field == 'foo'
        assert s['expr'].include_zero == True


class Test_dodge(object):

0 View Source File : plot.py
License : MIT License
Project Creator : PatrikHlobil

def pieplot(
    source,
    data_cols,
    colormap,
    hovertool,
    hovertool_string,
    figure_options,
    xlabelname,
    **kwargs,
):

    """Creates a Pieplot from the provided data."""

    # Determine Colormap for Pieplot:
    colormap = get_colormap(colormap, len(source["__x__values"]))
    source["color"] = colormap

    max_col_stringlength = max([len(col) for col in data_cols])

    # Create Figure for Pieplot:
    plot_width = figure_options["plot_width"]
    plot_height = figure_options["plot_height"]
    title = figure_options["title"]
    toolbar_location = None
    x_range = (-1.4 - 0.05 * max_col_stringlength, 2)
    y_range = (-1.2, 1.2)
    p = figure(
        plot_width=plot_width,
        plot_height=plot_height,
        title=title,
        toolbar_location=toolbar_location,
        x_range=x_range,
        y_range=y_range,
    )
    p.axis.axis_label = None
    p.axis.visible = False
    p.grid.grid_line_color = None

    # Calculate angles for Pieplot:
    for col in data_cols:
        source[col + "_angle"] = source[col] / source[col].sum() * 2 * np.pi

    # Make Pieplots:
    for i, col in list(enumerate(data_cols))[::-1]:
        inner_radius = float(i) / len(data_cols)
        outer_radius = float(i + 0.9) / len(data_cols)
        source["inner_radius"] = [inner_radius] * len(source["__x__values"])
        source["outer_radius"] = [outer_radius] * len(source["__x__values"])

        legend_parameter_name = "legend_field"
        if i == 0:
            kwargs[legend_parameter_name] = "__x__values_original"
            print(kwargs[legend_parameter_name])
        else:
            kwargs.pop(legend_parameter_name, None)

        if "line_color" not in kwargs:
            kwargs["line_color"] = "white"

        glyph = p.annular_wedge(
            x=0,
            y=0,
            inner_radius="inner_radius",
            outer_radius="outer_radius",
            start_angle=cumsum(col + "_angle", include_zero=True),
            end_angle=cumsum(col + "_angle"),
            fill_color="color",
            source=source,
            **kwargs,
        )

        # Add annotation:
        if len(data_cols) > 1:
            text_source = {
                "__x__values": [-1.3 - 0.05 * max_col_stringlength],
                "y": [0.5 - 0.3 * i],
                "text": [col],
            }
            p.text(
                x="__x__values",
                y="y",
                text="text",
                text_font_style="bold",
                source=text_source,
            )

            p.line(
                x=[-1.3 - 0.04 * (max_col_stringlength - len(col)), 0],
                y=[0.5 - 0.3 * i, -(inner_radius + outer_radius) / 2],
                line_color="black",
            )

        # Define hovertool and add to Pieplot:
        if hovertool:
            my_hover = HoverTool(renderers=[glyph])
            if hovertool_string is None:
                my_hover.tooltips = [
                    (xlabelname, "@__x__values_original"),
                    (col, "@{%s}" % col),
                ]
            else:
                my_hover.tooltips = hovertool_string
            p.add_tools(my_hover)

    return p


def mapplot(df, x, y, **kwargs):

0 View Source File : render.py
License : MIT License
Project Creator : sfu-db

def pie_viz(
    df: pd.DataFrame,
    nrows: int,
    col: str,
    plot_width: int,
    plot_height: int,
    pie: Pie,
) -> Tuple[Panel, List[str]]:
    """
    Render a pie chart
    """
    # pylint: disable=too-many-arguments
    npresent = df[col].sum()
    df.index = list(df.index)  # for CategoricalIndex to normal Index
    if nrows > npresent:
        df = df.append(pd.DataFrame({col: [nrows - npresent]}, index=["Others"]))
    df["pct"] = df[col] / nrows * 100
    df["angle"] = df[col] / nrows * 2 * np.pi

    tooltips = [(col, "@index"), ("Count", f"@{{{col}}}"), ("Percent", "@pct{0.2f}%")]
    fig = Figure(
        plot_width=plot_width,
        plot_height=plot_height,
        title=col,
        toolbar_location=None,
        tools="hover",
        tooltips=tooltips,
    )
    if pie.colors is None:
        color_list = list((CATEGORY20 * (len(df) // len(CATEGORY20) + 1))[0 : len(df)])
    else:
        color_list = list(pie.colors[0 : len(df)])
    df["colour"] = color_list
    df.index = df.index.astype(str)
    df.index = df.index.map(lambda x: x[:13] + "..." if len(x) > 13 else x)

    pie = fig.wedge(
        x=0,
        y=1,
        radius=0.9,
        start_angle=cumsum("angle", include_zero=True),
        end_angle=cumsum("angle"),
        line_color="white",
        fill_color="colour",
        source=df,
    )
    legend = Legend(items=[LegendItem(label=dict(field="index"), renderers=[pie])])
    legend.label_text_font_size = "8pt"
    fig.add_layout(legend, "left")
    tweak_figure(fig, "pie")
    fig.axis.major_label_text_font_size = "0pt"
    fig.axis.major_tick_line_color = None
    return Panel(child=row(fig), title="Pie Chart"), color_list


def hist_viz(