import plotly.graph_objects as go
import numpy as np
def draw_one_cloud(cloud, color='blue'):
fig = go.Figure(data=[go.Scatter3d(
x=cloud[:, 0],
y=cloud[:, 1],
z=cloud[:, 2],
mode='markers',
marker=dict(
size=4,
color=color, # 设置所有点的颜色
opacity=0.8
)
)])
# 设置图形的布局
fig.update_layout(
scene=dict(
xaxis_title='X Axis',
yaxis_title='Y Axis',
zaxis_title='Z Axis'
),
margin=dict(r=0, l=0, b=0, t=0)
)
fig.show()
# 打印总共绘制的点数
print(f"Total number of points: {cloud.shape[0]}")
def draw_multiple_clouds(clouds, colors):
fig = go.Figure()
for cloud, color in zip(clouds, colors):
fig.add_trace(go.Scatter3d(
x=cloud[:, 0],
y=cloud[:, 1],
z=cloud[:, 2],
mode='markers',
marker=dict(
size=4,
color=color, # 设置点的颜色
opacity=0.8
)
))
# 设置图形的布局
fig.update_layout(
scene=dict(
xaxis_title='X Axis',
yaxis_title='Y Axis',
zaxis_title='Z Axis'
),
margin=dict(r=0, l=0, b=0, t=0)
)
fig.show()
# 打印总共绘制的点数
# total_points = sum(cloud.shape[0] for cloud in clouds)
# print(f"Total number of points: {total_points}")
# 生成多个点云数据
cloud1 = np.random.rand(1000, 3) * 10
cloud2 = np.random.rand(1000, 3) * 10 + 15 # 平移点云2,使其与点云1不重叠
cloud3 = np.random.rand(1000, 3) * 10 + 30 # 平移点云3,使其与点云1、2不重叠
# 定义不同点云的颜色
colors = ['blue', 'red', 'green']
# 绘制多个点云并设置颜色
draw_multiple_clouds([cloud1, cloud2, cloud3], colors)
pthon 绘制3d立体点云
于 2024-06-24 16:55:12 首次发布