Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Animation frames changing the figure

I’ve a figure with 3D and 2D plots as shown below. However, whenever I add frames to it, it messes up completely. I can’t figure out what I’m doing wrong. Below’s the format of the plot grid. It says the plot on location (2, 3) is empty, which it should not. Although, I don’t know if this is the cause of the problem.

[ (1,1) scene1 ]  [ (1,2) x1,y1            -       ]
[ (2,1) scene2 ]         |              (empty)     
[ (3,1) x2,y2 ]          |                 |        

Here is what I want. I just remove the frames and everything plots as I want, except the animation doesn’t work.

Here is what it looks like after adding the frames. Notice projections are added in 3D plots. There’re new colorbars on the right, which don’t belong to any plot. And the Y data for the second 3D plot is complete wrong. Some traces in the line plot on right are missing. Etc.

The frames are just for the three plots on the left. Here is the code for frames:

plotly_frames = []
for frame in frames:
    frames_dict = dict(data=[dict(z=frame.final_mp_ranges,
                                  type='surface',
                                  scene='scene1',
                                  ),
                             dict(z=frame.final_mp_errors,
                                  type='surface',
                                  scene='scene2',
                                  ),
                             dict(x=xx.flatten(),
                                  y=yy.flatten(),
                                  type='scatter',
                                  xaxis='x2',
                                  yaxis='y2',
                                  marker=dict(
                                      size=frame.final_mp_coverages.flatten(),
                                      color=np.absolute((frame.or_mp_coverage-frame.final_mp_coverages).flatten()),
                                  ),
                                  text=get_coverage_labels(signal_map_size,
                                                           frame.final_mp_coverages,
                                                           frame.or_mp_coverage - frame.final_mp_coverages).flatten(),
                                  ),
                             ],
                       traces=range(3),
                       name=frame.timestamp,
                       )
    plotly_frames.append(frames_dict)

And here is the code for the whole figure.

Thanks for the help.

I figured out what is happening. Still don’t know how to fix it though.

The projections and colorbars are from three traces being moves from the large scatter plot on the right to the three subplots on the left. I have no idea what is causing them to move there though.

Finally got. So if anyone gets here looking for answer, here you go.

It was the traces argument in frames dict. The traces has to be contain the index of the traces that you want to update. So if you did append_trace four times, and you want to update the 3rd one, the traces will be equal to [3]. In my case above, it had to be [6, 7, 8]; I had 9 traces and wanted to update the last three. This changed based on the order you use append_traces.

Thanks plotly for the wonderful documentation.

1 Like