Is it possible to update multiple traces with different value arrays in one go?

I have a 3 orthogonal surfaces that slice through a 3D data cube, and I have a slider that navigates a 4th dimension.

Whenever I move the slider, I update the 3 slices one at a time:

xy_array = np.array([...]) # array of shape (nx, ny)
yz_array = np.array([...]) # array of shape (ny, nz)
zx_array = np.array([...]) # array of shape (nz, nx)
arrays = [xy_array, yz_array, zx_array]
for i in range(3):[i].surfacecolor = arrays[i]

The problem I have is that I can see each surface being updated one after the other, which does not have the best feel, the slices feel disconnected and the interaction with the slider quite laggy.

My question is can I update all 3 surfaces in one go?
I am aware of the update_traces method but that only lets you update all traces with the same values. There is also the for_each_trace method, but this would just be equivalent to indexing the elemtns one by one, right?

I was thinking of something like

fig.update_traces({"surfacecolor": xy_array},
                  {"surfacecolor": yz_array},
                  {"surfacecolor": zx_array})


fig.add_trace(go.Surface(..., name="surf_xy"))
fig.add_trace(go.Surface(..., name="surf_yz"))
fig.add_trace(go.Surface(..., name="surf_zx"))
fig.update_traces({"surfacecolor": xy_array, "selector": {"name": "surf_xy"}},
                  {"surfacecolor": yz_array, "selector": {"name": "surf_yz"}},
                  {"surfacecolor": zx_array, "selector": {"name": "surf_zx"}})

Alternatively, is it possible to pause the update of the figure until all 3 surfacecolors have been updated, and then display the new surfaces in the figure?
For instance:

for i in range(3):[i].surfacecolor = arrays[i]

(I am actually using FigureWidget, in case that makes any difference.)

Many thanks for any help!

1 Like