【问题标题】:Add a point to a scatter plot in python在python中向散点图添加一个点
【发布时间】:2018-10-12 08:58:07
【问题描述】:

我有一个点云,为了展示它,我使用了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'

【问题讨论】:

    标签: python matplotlib plot point-clouds centroid


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      相关资源
      最近更新 更多