💸 Reduce costs by consolidating proprietary analytics & reporting software to open-source & Dash.
Challenge us to replace your analytics with Dash and reduce costs.

Is there any way to update one specific trace's layout?

Hey all,
I had what I thought was a very simple problem but it has sent me through a rabbit hole and I guess I’m missing something. I was trying to make a very simple 2x1 plot. The first plot was a stacked bar plot, and the second one is a regular bar plot with a scatter, like this:

In this case it isn’t really a problem, but if I wanted to use two different barmodes for my subplots, what could I do? Because barmode is linked to the figure’s layout I can’t seem to find a way to plot two types of barmodes in different subplots.

My code goes something like this:

    trace1 = go.Bar(x=dfv['date'], y=dfv['used'],
                         marker_color='red')
    trace2 = go.Bar(x=dfv.fecha, y=dfv.disponible
                     marker_color='green')
    fig.append_trace(trace1, 1, 1)
    fig.append_trace(trace2, 1, 1)

    trace3 = go.Bar(x=dfv.date, y=dfv.total, name='Total ')
    trace4 = go.Scatter(x=dfv['date'], y=dfv['percentage'], name='% ')
    fig.append_trace(trace3, 2, 1)
    fig.append_trace(trace4, 2, 1)
    fig.update_layout(barmode='stack')

Si if trace4 was also a bar and I wanted non-stacked bars for this one, what could I do?
Thanks

Edit: I saw px.bar() has a barmode argument, but it has weird interactions with add_trace() (or I’m also missing something, so that kinda worked, but the label was lost and I had to updated several properties with udpate_traces. I also tried cufflinksiplot but barmode was ignored by Dash.

Hi @Juanouo you are right, the barmode is a layout attribute so it is not possible to have different barmodes in different subplots :-(. You would have to go with several figures (two dcc.Graph in a Dash app), each of them with its layout and corresponding attributes.

Thanks for the answer @Emmanuelle. Isn’t it a bit weird that barmode is a layout property? Seems more like a figure property to me. Do you know what’s the logic to that?