Fig.update_layout only affecting first subplot

I’m trying to have multiple subplots with no grid-lines on the yaxis. It seems like whatever I pass in to fig.update_layout is only affecting my first subplot.

fig = make_subplots(rows=1, cols=2)

fig.add_trace(
    go.Scatter(
        x=list(range(sample_points)),
        y=data_gx.iloc[scene],
        name='X-axis',
        line=dict(color='green', width=2)
    ),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(
        x=list(range(sample_points)),
        y=data_ax.iloc[scene],
        name='X-axis',
        line=dict(color='green', width=2)
    ),
    row=1, col=2
)

fig.update_layout(
    yaxis=dict(showgrid=False)
)

show

It’s because yaxis specifically refers to the first subplot, yaxis2 to the second etc. You can do

fig.update_layout(
    yaxis=dict(showgrid=False),
    yaxis2=dict(showgrid=False)
)

or alternatively, if you want to update all yaxes at the same time, use fig.update_yaxes:

fig.update_yaxes(showgrid=False)
3 Likes

Hi @Emmanuelle I’ve been struggling a bit with my update_layout. I am doing heatmaps subplots. I see that from each call, at first, figure state is empty, but then it’s already populated, even when I always use make_suplots call and assign thereafter.

Anyway, there is a strange bug related to update_layout or maybe I am doing something wrong.

Basically, I want to have an option to either use a shared colorbar or not. This option is in a dropdown state component. For this, when creating traces, I use or not the coloraxis attribute. However it seems that once I use coloraxis=‘coloraxis’ (to share the said colorbar), it gets “stuck” at the figure data and layout attributes.

How should I correctly use update_layout in order to fix this. Some code below:

def calc_traces(z):
            trace = {
                'type': 'heatmap',
                'z': z.to_numpy(),
                'x': z.columns.tolist(),
                'y': z.index.tolist(),
                'colorscale': 'jet',
                'showscale': False,
                 'xgap': 1,
                'ygap': 1,
                }
            if global_rend_br == 'global':
                trace['coloraxis'] = 'coloraxis'
...
fig = make_subplots(rows=1, cols=8, 
                shared_yaxes=True,
                subplot_titles=(
                    'Ingresos', 'Siniestros', 'Partic. Benef.', 'Var. Prov.', 'Gastos', 'O. Ingr.', 'O. Gastos', 'Margen Br.'),
                column_widths=[0.4, 0.5, 0.2, 0.2, 0.3, 0.2, 0.4, 0.1]
                                    )
        *# FRESH LAYOUT EACH CALL?*
        layout = {}
        layout = deepcopy(hlp.heatmap_lay)
        layout['xaxis'] = {}
        
        # adding traces
        for i, trace in enumerate(traces, start=1):
            fig.append_trace(trace, 1, i)
            if i == 1:
                layout['xaxis']['visible'] = False
            if i >= 2:
                layout['xaxis'+str(i)] = {}
                layout['xaxis'+str(i)]['visible'] = False
        
        layout['autosize'] = True
        layout['height'] = 1200
        layout['title_text'] = "RENDIMIENTO BRUTO DE CUENTA TÉCNICA"
        if global_rend_br == 'global':
            layout['coloraxis'] = {
                'colorscale': 'jet',
                'showscale': False
                }
        fig.update_layout(**layout)
...
       return fig

UPDATE: Done some more tests, and I think the bug is around the coloraxis reference (the one used to share a colorbar accross heatmaps subplots), as once it’s used, it gets kind of stuck in the state layout…