首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在python中多次使用ax.voxels方法后修复限制

如何在python中多次使用ax.voxels方法后修复限制
EN

Stack Overflow用户
提问于 2019-08-16 23:57:54
回答 1查看 274关注 0票数 1

我正在研究从激光雷达接收到的三维点云。我将大量的点(高达1000-1亿)分成立方体,调查它们的位置,并使用Axes3D.voxels方法将结果显示在单独的体素中。然而,在多次使用此方法后,我在设置适当的Axes3D限制时遇到了一些问题。

我定义了add_voxels函数,以便从输入的立方体位置的np.array立即显示体素:

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import itertools

def add_voxels(true_ids, ax):
    shape_of_filled = true_ids.max(axis=0) + 1  # shape of building
    filled = np.zeros(shape_of_filled)
    for n in true_ids:
        filled[n] = 1
    x, y, z = np.indices(np.array(shape_of_filled) + 1)
    return ax.voxels(x,y,z, filled)```

Then use it to plot my two clouds of cubes:

fig = plt.gcf()  # get a reference to the current figure instance
ax = fig.gca(projection='3d')  # get a reference to the current axes instance
cubecloud1 = np.array(list(itertools.product(range(2,4), range(2,4), range(2,4))))
cubecloud2 = np.array(list(itertools.product(range(4,7), range(4,7), range(4,7))))
add_voxels(cubecloud2, ax)
add_voxels(cubecloud1, ax)
plt.show()

它导致了体素位置显示的不良限制:

我希望所有组件都显示在正确的边界框中,如下所示:

或者,至少这样(假设边界框也包括不可见的体素):

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-17 01:50:36

我只能通过显式设置轴限制来实现这一点:

代码语言:javascript
复制
# [...]
faces2 = add_voxels(cubecloud2, ax)
faces1 = add_voxels(cubecloud1, ax)
points = list(faces1.keys()) + list(faces2.keys())
data = list(zip(*points))
xmin = min(data[0])
xmax = max(data[0])
ymin = min(data[1])
ymax = max(data[1])
zmin = min(data[2])
zmax = max(data[2])
ax.set_xlim3d(xmin, xmax)
ax.set_ylim3d(ymin, ymax)
ax.set_zlim3d(zmin, zmax)
plt.show()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57527709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档