使用 3D Scatterplo 叠加 3D 轮廓 [已关闭]

问题描述 投票:0回答:1

基本上,我有一个程序可以生成一条穿过输入点的非常基本的 3D 线。我想用 PLT 绘制这条线的图表,然后将用户的输入点(存储为 n,3 数组)放在生成的图表之上。一旦我的计算机再次连接到 Wi-Fi,我就会发布我的代码,因为这是在我的手机上(现在可以在 Wi-Fi 线路上工作)。所需时间从 1 小时到 1 天不等。希望大家对我有耐心!

我尝试过使用

scatter
方法和各种其他方法。我尝试创建两个不同的图形或子图并将它们合并在一起。我也尝试过更改散点图和线条的尺寸和数据输入。然而,每当我尝试将两者合并在一起时,线条就会消失,只剩下散点图。

python numpy matplotlib scatter-plot matplotlib-3d
1个回答
-1
投票

下面的示例在 3D 中绘制一条线,并覆盖任意用户定义的点。

import numpy as np
import matplotlib.pyplot as plt

#Mock data
rad = np.linspace(0, 10)
#n_rows x (x, y, z) (i.e. n x 3 shape)
line_3d = np.stack([np.sin(rad), np.cos(rad), rad], axis=1)

#Supppose user has a different number of points
user_points = np.concatenate([line_3d]*2, axis=0)
user_points = user_points + np.random.uniform(0, 0.3, size=user_points.shape)

#Initialise plot
ax = plt.figure(figsize=(6, 6)).add_subplot(projection='3d')
ax.view_init(azim=45, elev=20, roll=0)

#Plot the line
ax.plot3D(line_3d[:, 0], line_3d[:, 1], line_3d[:, 2], linewidth=5 , color='m')
#Add user's points
ax.scatter3D(user_points[:, 0], user_points[:, 1], user_points[:, 2],
             c=user_points[:, 2], s=50, edgecolor='k', linewidth=2)

#Label plot
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title('3D line plus user-defined points')
© www.soinside.com 2019 - 2024. All rights reserved.