Hello,
I’m trying to make a 3D scatter plot with plotly which has an animation frame for column “predicted-time-point”, and shows data for “old-time-point” in each frame by their x,y,z values. However, the animation frame slider is not in the numerical order. It goes like 18, 15, 8, 4 etc. When
fig = px.scatter_3d(df_high_res, x='x', y='y', z='z', color='old-time-point',
animation_frame='predicted-time-point',
# color_discrete_map=color_map,
# color_discrete_sequence=custom_color_scale, # Use custom color scale
title='3D Scatter Plot with Animation Frames',
labels={'old-time-point': 'Old Time Point', 'predicted-time-point': 'Predicted Time Point',
'new-time-point': 'New Time Point', 'x': 'X', 'y': 'Y', 'z': 'Z'},
hover_data=['old-time-point', 'predicted-time-point', 'new-time-point', 'x', 'y', 'z'],
)
fig.update_layout(scene=dict(aspectmode='data'))
fig.update_traces(marker_size = 4)
fig.update_layout(
scene=dict(
xaxis=dict(title='X'),
yaxis=dict(title='Y'),
zaxis=dict(title='Z'),
),
title=f'3D Scatter Plot for Cluster {cl_info[-1]}',
width=900,
height=900,
showlegend=True,
legend=dict(title='Time-Point')
)
fig.show()
I sort the dataframe before plotting with df_high_res = df_high_res.sort_values(by=['predicted-time-point', 'old-time-point'])
, then I loose some data points in the figures. Instead of three old-time-point` categories, I only see two. A simple print(df_high_res[‘old-time-point’].unique()) shows that the category is still there, but it doesn’t appear in the plots. How can I solve it and have them plotted with discrete colors scheme?