I am trying to display 3 sets of X/Y coordinates on an animated plotly scatter graph in which the animation key is time. Currently my workaround was to add all the coordinate sets into the same dataframe however I believe this will cause me problems as I need to change marker properties to easily distinguish between each point.
This is what my workaround looks like:
This is how I am generating the graph:
x1_trim += x2_trim
x1_trim += x3_trim
y1_trim += y2_trim
y1_trim += y3_trim
d = {
"x1": x1_trim,
"y1": y1_trim,
"time": time_trim
}
df = pd.DataFrame(d)
#Default x and y axis
x_range = [-1,1]
y_range = [-1,1]
fig = px.scatter(df, x="x1", y="y1", animation_frame="time", range_x=x_range, range_y=y_range)
fig.add_shape(type="rect",x0=-0.5, y0=-0.5, x1=0.5, y1=0.5, line=dict(color="Green",width=2))
As you can see I'm adding my x2/y2 and x3/y3 data onto the end of my x1/y1 list, how would I keep these separate whilst still having all the information on my animated plot? I was trying to display multiple scatter graphs on the same plot however never managed to get it working.
My solution attempt:
#Building the dataframe and drawing graph
d1 = {
"x": x1_trim,
"y": y1_trim,
"time": time_trim
}
d2 = {
"x": x2_trim,
"y": y2_trim,
"time":time_trim
}
d3 = {
"x": x3_trim,
"y": y3_trim,
"time": time_trim
}
dfs = {"d1": d1, "d2": d2, "d3": d3}
fig = go.Figure()
for i in dfs:
fig = fig.add_trace(go.Scatter(x = dfs[i]["x"], y = dfs[i]["y"], name = i, animation_frame=dfs[0]["time"] ))