def bar_plot_times_momentum()

in experiments/plot_experiments.py [0:0]


def bar_plot_times_momentum(times_df):
    """Plots runtimes for given problem"""
    df = times_df.copy()
    df["error (1st quartile)"] = df["time (median)"] - df["time (1st quartile)"]
    df["error (3rd quartile)"] = df["time (3rd quartile)"] - df["time (median)"]

    fig_no_mom = px.bar(
        df[df["run_name"] == "no_mom"],
        x="sketch_size",
        y="time (median)",
        # color=COLOR_DICT["no_mom"],
        barmode="group",
        error_y="error (3rd quartile)",
        error_y_minus="error (1st quartile)",
    )
    fig_no_mom.update_xaxes(type='category')
    fig_no_mom.update_traces(marker_color=COLOR_DICT["no_mom"])
    fig_no_mom.update_layout(
        margin={"l": 20, "r": 20, "t": 20, "b": 20},
        template="plotly_white",
        font=dict(size=20,),
        xaxis_title="sketch size",
        yaxis_title="time (seconds)",
    )

    fig_cst_mom = px.bar(
        df[df["run_name"] == "cst_mom"],
        x="sketch_size",
        y="time (median)",
        # color=COLOR_DICT["cst_mom"],
        barmode="group",
        error_y="error (3rd quartile)",
        error_y_minus="error (1st quartile)",
    )
    fig_cst_mom.update_xaxes(type='category')
    fig_cst_mom.update_traces(marker_color=COLOR_DICT["cst_mom"])
    fig_cst_mom.update_layout(
        margin={"l": 20, "r": 20, "t": 20, "b": 20},
        template="plotly_white",
        font=dict(size=20,),
        xaxis_title="sketch size",
        yaxis_title="time (seconds)",
    )

    fig_inc_mom = px.bar(
        df[df["run_name"] == "inc_mom"],
        x="sketch_size",
        y="time (median)",
        # color=COLOR_DICT["inc_mom"],
        barmode="group",
        error_y="error (3rd quartile)",
        error_y_minus="error (1st quartile)",
    )
    fig_inc_mom.update_xaxes(type="category")
    fig_inc_mom.update_traces(marker_color=COLOR_DICT["inc_mom"])
    fig_inc_mom.update_layout(
        margin={"l": 20, "r": 20, "t": 20, "b": 20},
        template="plotly_white",
        font=dict(size=20,),
        xaxis_title="sketch size",
        yaxis_title="time (seconds)",
    )

    # Grouped bar plot summarizing all results
    fig_grouped = go.Figure(data=[
        go.Bar(
            name="no momentum",
            x=df["sketch_size"],
            y=df[df["run_name"] == "no_mom"]["time (median)"],
            error_y=dict(
                array=df[df["run_name"] == "no_mom"]["error (3rd quartile)"],
                arrayminus=df[df["run_name"] == "no_mom"]["error (1st quartile)"]
            ),
            marker_color=COLOR_DICT["no_mom"],
        ),
        go.Bar(
            name="increasing momentum",
            x=df["sketch_size"],
            y=df[df["run_name"] == "inc_mom"]["time (median)"],
            error_y=dict(
                array=df[df["run_name"] == "inc_mom"]["error (3rd quartile)"],
                arrayminus=df[df["run_name"] == "inc_mom"]["error (1st quartile)"]
            ),
            marker_color=COLOR_DICT["inc_mom"],
        ),
        go.Bar(
            name="constant momentum",
            x=df["sketch_size"],
            y=df[df["run_name"] == "cst_mom"]["time (median)"],
            error_y=dict(
                array=df[df["run_name"] == "cst_mom"]["error (3rd quartile)"],
                arrayminus=df[df["run_name"] == "cst_mom"]["error (1st quartile)"]
            ),
            marker_color=COLOR_DICT["cst_mom"],
        ),
    ])

    # Change the bar mode
    fig_grouped.update_layout(barmode='group')

    # Legend position
    fig_grouped.update_layout(
        margin={"l": 20, "r": 20, "t": 20, "b": 20},
        template="plotly_white",
        font=dict(size=20,),
        xaxis_title="sketch size",
        yaxis_title="time (seconds)",
        legend=dict(
            yanchor="top",
            y=0.99,
            x=0.01,
            xanchor="left",
        )
    )

    return fig_no_mom, fig_cst_mom, fig_inc_mom, fig_grouped