I want to animate lines of different number in each frame.
Please refer to the code. the data has 3 frame divided by “ts”. The 1st and 3rd frame have 2 lines. The 2nd frame has 1 line only.
But the final figure shows that, the 2nd picture has two lines.
import plotly
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
df2 = pd.DataFrame(
np.array([
[0, 0, 0, 1],
[0, 0, 1, 2],
[0, 1, 1, 0],
[0, 1, 2, 1],
[1, 0, 2, 1],
[1, 0, 3, 2],
[2, 0, 2, 3],
[2, 0, 3, 4],
[2, 1, 3, 2],
[2, 1, 4, 3],
]),
columns=["ts", "id", "x", "y"]
)
fig2 = px.line(df2,
x="x",
y="y",
animation_frame="ts",
animation_group="id",
line_group="id",
)
fig2
The 2nd picture has two lines(two lines with one head as the others tail ). I hope keep line segment [2, 1] to [3, 2] only.
What is the best way to solve my problem?