본문 바로가기

Python

3D points data scatter plot

반응형
import pickle

# Load tensor from the file
with open('tensor.pkl', 'rb') as f:
    loaded_tensor = pickle.load(f)

grids = loaded_tensor[0] # num_cams x num_depth x H x W x 3
grids = grids.view(-1, 3).to('cpu').numpy()

import plotly.graph_objects as go

# Sample data: sequence of 3D points (x, y, z)
x_points = list(grids[:, 0])
y_points = list(grids[:, 1])
z_points = list(grids[:, 2])

# Create a 3D scatter plot using plotly
fig = go.Figure(data=[go.Scatter3d(
    x=x_points,
    y=y_points,
    z=z_points,
    mode='markers+lines',  # You can use 'markers', 'lines' or 'markers+lines'
    marker=dict(
        size=8,
        color=z_points,  # Color by the z values
        colorscale='Viridis',  # Choose a color scale
        colorbar=dict(title="Z Values")
    ),
    line=dict(
        color='blue',
        width=2
    )
)])

# Set plot layout and axis labels
fig.update_layout(scene=dict(
    xaxis_title='X Axis',
    yaxis_title='Y Axis',
    zaxis_title='Z Axis'),
    title="3D Plot of a Sequence of Points"
)

# Show the plot
fig.show()