I have a script continue generating 3d coordinate
I need to visualize it like a video with play and stop and manipulation
I saw the solution on 3D Scatter Animation
but unable to set all coordinate with connection and when the script generate a new coordinate the plot update to new coordinate with connections
this is my code now
def plot_3d(First_set, Sec_set):
print("first_parameter: ", First_set.shape)
print("first_parameter: ", Sec_set.shape)
import numpy as np
import plotly.graph_objects as go
# First set of 3D data
data1 = np.array(First_set)
# Second set of 3D data
data2 = np.array(Sec_set)
connections = [(0, 1), (1, 2), (2, 3), (3, 4), (0, 5), (5, 6), (6, 7), (7, 8),
(0, 9), (9, 10), (10, 11), (11, 12), (0, 13), (13, 14), (14, 15),
(15, 16), (0, 17), (17, 18), (18, 19), (19, 20)]
# Create the 3D scatter plot
fig = go.Figure()
x1 = []
y1 = []
z1 = []
for connection in connections:
idx1, idx2 = connection
x_conn = [data1[0, idx1, 0], data1[0, idx2, 0], None]
y_conn = [data1[0, idx1, 1], data1[0, idx2, 1], None]
z_conn = [data1[0, idx1, 2], data1[0, idx2, 2], None]
x1.extend(x_conn)
y1.extend(y_conn)
z1.extend(z_conn)
fig.add_trace(go.Scatter3d(x=x1, y=y1, z=z1, mode='lines+markers', name='obj2'))
x2 = []
y2 = []
z2 = []
for connection in connections:
idx1, idx2 = connection
x_conn = [data2[0, idx1, 0], data2[0, idx2, 0], None]
y_conn = [data2[0, idx1, 1], data2[0, idx2, 1], None]
z_conn = [data2[0, idx1, 2], data2[0, idx2, 2], None]
x2.extend(x_conn)
y2.extend(y_conn)
z2.extend(z_conn)
fig.add_trace(go.Scatter3d(x=x2, y=y2, z=z2, mode='lines+markers', name='obj4'))
# Update layout
fig.update_layout(scene=dict(aspectratio=dict(x=1, y=1, z=1), aspectmode='manual'), width=720)
# Show the plot
fig.show()
import numpy as np
First_set = np.random.rand(1, 50, 3)
Sec_set = np.random.rand(1, 50, 3)
plot_3d(First_set, Sec_set)