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…