I'm trying to animate multiple tracks with Python plotly.
The code is:
import pandas as pd
import plotly.express as px
df = pd.read_csv("orbite.csv")
fig=px.scatter(df,x="X1",y="Y1",animation_frame="time",range_x=[-6,1],range_y=[-5,2])\
fig.add_scatter(df,x="X2",y="Y2",animation_frame="time",range_x=[-6,1],range_y=[-5,2])
fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = 20
fig.update_layout(transition = {"duration": 20})
fig.show()
以下是数据文件:
time X1 Y1 X2 Y2
0 1 -0.001000 0.000000 0.000000 10.000000
1 2 -0.001000 0.000000 -0.035000 9.940000
2 3 -0.000951 0.000049 -0.070000 9.890000
3 4 -0.000853 0.000148 -0.105000 9.830000
4 5 -0.000707 0.000297 -0.140000 9.780000
该程序只有一个动画运行良好,但如果我加上fig.add_scatter()
,我会得到错误:
The 'alignmentgroup' property is a string and must be specified as:
- A string
- A number that will be converted to a string
怎么了?