Black Lives Matter. Please consider donating to Black Girls Code today.

How to update trace of imshow()?

The following code works nicely in my notebook.

img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
                    [[0, 255, 0], [0, 0, 255], [255, 0, 0]],
                    [[0, 255, 255], [255, 0, 255], [0, 255, 0]]
                   ], dtype=np.uint8)
fig_matrix = go.FigureWidget(go.Image(z=img_rgb))
fig.show()

I would like to update the trace of the figure, and have tried something like

img_rgb_2 = np.array([[[0, 0, 0], [0, 255, 0], [0, 0, 255]],
                    [[0, 0, 0], [0, 0, 255], [255, 0, 0]],
                    [[0, 255, 255], [255, 0, 255], [0, 255, 0]]
                   ], dtype=np.uint8)
fig_matrix.update_traces(z=img_rgb_2)

which does not work. How do I update the trace of fig_matrix?

I figured it out myself after reading this tutorial

fig_matrix.data[0].z = img_rgb_2
1 Like