analyses/utils.py
def my_shaded_trace(
    fig: go.Figure, df: DataFrame, d: str, color: str, grps: list, key: str, col=None, row=None, show_legend=True
):
    """
    Add a shaded trace to a plotly figure

    Parameters
    ----------
    fig : go.Figure
        The figure to which the trace will be added
    df : DataFrame
        The dataframe containing the data
    d : str
        The dynamics type of concern
    color : str
        The color of the trace
    grps : list
        The legend groups
    key : str
        The data key such as "tau" or "qddot" or "qddot_joints" or "q"
    """
    my_boolean = df["dynamics_type_label"] == d

    c_rgb = px.colors.hex_to_rgb(color)
    c_alpha = str(f"rgba({c_rgb[0]},{c_rgb[1]},{c_rgb[2]},0.2)")

    fig.add_scatter(
        x=df[my_boolean]["n_shooting_tot"],
        y=df[my_boolean][key],
        mode="markers",
        marker=dict(
            color=color,
            size=3,
        ),
        name=d,
        legendgroup=grps,
        showlegend=False,
        row=row,
        col=col,
    )

    x_shoot = sorted(df[my_boolean]["n_shooting_tot"].unique())

    fig.add_scatter(
        x=x_shoot,
        y=get_all(df, d, key, "mean"),
        mode="lines",
        marker=dict(color=color, size=8, line=dict(width=0.5, color="DarkSlateGrey")),
        name=d,
        legendgroup=grps,
        row=row,
        col=col,
        showlegend=show_legend,
    )

    y_upper = get_all(df, d, key, "ci_up")
    y_upper = [0 if math.isnan(x) else x for x in y_upper]
    y_lower = get_all(df, d, key, "ci_low")
    y_lower = [0 if math.isnan(x) else x for x in y_lower]

    fig.add_scatter(
        x=x_shoot + x_shoot[::-1],  # x, then x reversed
        y=y_upper + y_lower[::-1],  # upper, then lower reversed
        fill="toself",
        fillcolor=c_alpha,
        line=dict(color="rgba(255,255,255,0)"),
        hoverinfo="skip",
        showlegend=False,
        legendgroup=grps,
        row=row,
        col=col,
    )
    return fig

    Add a shaded trace to a plotly figure

    Parameters
    ----------
    fig : go.Figure
        The figure to which the trace will be added
    df : DataFrame
        The dataframe containing the data
    d : str
        The dynamics type of concern
    color : str
        The color of the trace
    grps : list
        The legend groups
    key : str
        The data key such as "tau" or "qddot" or "qddot_joints" or "q"
    
Add a shaded trace to a plotly figure
Parameters


Add a shaded trace to a plotly figure Parameters
def my_shaded_trace(
    fig: go.Figure, df: DataFrame, d: str, color: str, grps: list, key: str, col=None, row=None, show_legend=True
):
    my_boolean = df["dynamics_type_label"] == d
    c_rgb = px.colors.hex_to_rgb(color)
    c_alpha = str(f"rgba({c_rgb[0]},{c_rgb[1]},{c_rgb[2]},0.2)")
    fig.add_scatter(
        x=df[my_boolean]["n_shooting_tot"],
        y=df[my_boolean][key],
        mode="markers",
        marker=dict(
            color=color,
            size=3,
        ),
        name=d,
        legendgroup=grps,
        showlegend=False,
        row=row,
        col=col,
    )
    x_shoot = sorted(df[my_boolean]["n_shooting_tot"].unique())
    fig.add_scatter(
        x=x_shoot,
        y=get_all(df, d, key, "mean"),
        mode="lines",
        marker=dict(color=color, size=8, line=dict(width=0.5, color="DarkSlateGrey")),
        name=d,
        legendgroup=grps,
        row=row,
        col=col,
        showlegend=show_legend,
    )
    y_upper = get_all(df, d, key, "ci_up")
    y_upper = [0 if math.isnan(x) else x for x in y_upper]
    y_lower = get_all(df, d, key, "ci_low")
    y_lower = [0 if math.isnan(x) else x for x in y_lower]
    fig.add_scatter(
        x=x_shoot + x_shoot[::-1],  
        y=y_upper + y_lower[::-1],  
        fill="toself",
        fillcolor=c_alpha,
        line=dict(color="rgba(255,255,255,0)"),
        hoverinfo="skip",
        showlegend=False,
        legendgroup=grps,
        row=row,
        col=col,
    )
    return fig
def my_shaded_trace ( fig : go . Figure , df : DataFrame , d : str , color : str , grps : list , key : str , col = None , row = None , show_legend = True ) : my_boolean = df [ "dynamics_type_label" ] == d c_rgb = px . colors . hex_to_rgb ( color ) c_alpha = str ( f"rgba({c_rgb[0]},{c_rgb[1]},{c_rgb[2]},0.2)" ) fig . add_scatter ( x = df [ my_boolean ] [ "n_shooting_tot" ] , y = df [ my_boolean ] [ key ] , mode = "markers" , marker = dict ( color = color , size = 3 , ) , name = d , legendgroup = grps , showlegend = False , row = row , col = col , ) x_shoot = sorted ( df [ my_boolean ] [ "n_shooting_tot" ] . unique ( ) ) fig . add_scatter ( x = x_shoot , y = get_all ( df , d , key , "mean" ) , mode = "lines" , marker = dict ( color = color , size = 8 , line = dict ( width = 0.5 , color = "DarkSlateGrey" ) ) , name = d , legendgroup = grps , row = row , col = col , showlegend = show_legend , ) y_upper = get_all ( df , d , key , "ci_up" ) y_upper = [ 0 if math . isnan ( x ) else x for x in y_upper ] y_lower = get_all ( df , d , key , "ci_low" ) y_lower = [ 0 if math . isnan ( x ) else x for x in y_lower ] fig . add_scatter ( x = x_shoot + x_shoot [ : : - 1 ] , y = y_upper + y_lower [ : : - 1 ] , fill = "toself" , fillcolor = c_alpha , line = dict ( color = "rgba(255,255,255,0)" ) , hoverinfo = "skip" , showlegend = False , legendgroup = grps , row = row , col = col , ) return fig
Add a shaded trace to a plotly figure
Parameters
Add a shaded trace to a plotly figure Parameters
"""
    Add a shaded trace to a plotly figure

    Parameters
    ----------
    fig : go.Figure
        The figure to which the trace will be added
    df : DataFrame
        The dataframe containing the data
    d : str
        The dynamics type of concern
    color : str
        The color of the trace
    grps : list
        The legend groups
    key : str
        The data key such as "tau" or "qddot" or "qddot_joints" or "q"
    """ # x, then x reversed # upper, then lower reversed
fig
go.Figure
df
DataFrame
d
str
color
str
grps
list
key
str
col
row
show_legend