Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Lineplot overlapping when setting color input

Hey,

I am trying to create sort of caterpillar plot which is based on a dataframe containing information regarding the distributional properties of the posterior sample of the parameter. The idea is to utilize dash with filtering options. As I am running a hierarchical model, I would like to be able to compare the multiple audience parameters.

In the code, I am using plotly.express.line as my go to plot and than add different traces for mean and the Confidence interval bounds. The plot looks something like this.

The problem is that the lines overlap while I would like to have them above each other. I was trying different commands directly in the plotly.express.line or through update_traces(), however, I was not able to figure out how to meet my desired output. This is the current iteration of the code:

 # Plot BoxPlots
    fig = px.line(thin_data, x='effect', y='var_name', line_group='var_name', color=color_facet,
                  facet_col=dims_facet, facet_col_spacing=0.1)
    fig.update_traces(hovertemplate="<b> 90% CI Bounds </b> <br>%{x:.4f}",
                      marker_opacity=0.5)

    thick_line = px.line(thick_data, x='effect', y='var_name', line_group='var_name', color=color_facet,
                         facet_col=dims_facet, facet_col_spacing=0.1)
    thick_line.update_traces(line_width=5, marker_opacity=0.5,
                             hovertemplate="<b>50% CI Bounds</b> <br>%{x:.4f}")

    mean_line = px.scatter(mean_data, x='effect', y='var_name', color=color_facet,
                           facet_col=dims_facet, facet_col_spacing=0.1,
                           text='effect')
    mean_line.update_traces(hovertemplate="<b>Mean</b> <br>%{x:.4f}",
                            texttemplate="<b>%{text:.2f}</b>",
                            marker_size=15, textposition='top center',
                            textfont_size=15)

    add_trace = lambda x, y: fig.add_trace(x['data'][y])
    for plot in (thick_line, mean_line):
        trace_len = range(len(plot['data'])) if len(plot['data']) else 0
        for i in trace_len:
            add_trace(plot, i)

I know from experience that when using e.g. px.box() and setting the color as a column in the DataFrame, the resulting plot is not having overlapping boxplots - I would like to have that with the lineplot if possible. I also came across plotly.express.strip() which results in the desired outcome but I was not able to connect the points in order to create a line plot. I am thankful for any tips.

Thank you