在python中向散点图添加点

时间:2018-10-12 08:58:07

标签: python matplotlib plot point-clouds centroid

我有一个点云,为了显示它,我使用了matpyplot库。然后,我想在该图中添加一点,即该云的质心。这是我的代码

point_list, centroid_list = points(dataset[:, :7])
# take one point cloud 
points = np.array(point_list[0])
# take the centroid of that point cloud
centroid = np.array(centroid_list[0])
f = plt.figure(figsize=(15, 8))
ax = f.add_subplot(111, projection='3d')
ax.scatter(*np.transpose(points[:, [0, 1, 2]]), s=1, c='#FF0000', cmap='gray')
ax.plot(centroid, 'or') # this line doesn't work
plt.show()

绘制点云的线是我的问题,我不知道如何添加点。我试过其他线程中的一些解决方案,但它们不起作用。我想用其他颜色甚至更大的颜色绘制质心,例如使用散点图s=5, c='#00FF00'的表示法。

1 个答案:

答案 0 :(得分:1)

下面的工作代码应给您一些见识。在您的代码中,质心的尺寸/形状不统一。您可能要相应地调整行。

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import numpy as np

points = np.random.normal(size=(20,3))
# take the centroid of that point cloud
centroid = np.asarray([0.,0.,0.])
f = plt.figure(figsize=(15, 8))
ax = f.add_subplot(111, projection='3d')
ax.scatter(*np.transpose(points[:, [0, 1, 2]]), s=1, c='#FF0000', cmap='gray')
ax.plot([centroid[0]],[centroid[1]],[centroid[2]],'or') # this line doesn't work
plt.show()