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

Mathfux

我正在研究从激光雷达接收到的3D点云。我将大量的点(最多10-1亿个)分割为多维数据集,研究它们的位置并使用Axes3D.voxels方法将结果显示在单独的体素中但是,Axes3D在多次使用此方法设置适当的限制时,我会遇到一些问题

我定义add_voxels函数是为了从np.array输入的多维数据集的位置立即显示体素

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()

这会导致显示体素位置的限制很差:

我想将所有组件显示在这样的正确边界框中:

Or, at least, this (assuming bounding box includes invisible voxels too):

Håkon Hægland

I could only make this work by setting the axis limits explicitly:

# [...]
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()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Python中多次使用.get()?

如何在python中多次使用'if'循环?

如何使用Python在Elasticsearch中对对象执行多次聚合?

如何修复反应中的限制渲染循环

如何修复minSdkVersion 21中的DEX 64K方法限制?

使用reduce方法JS后修复

使用sudo运行后如何修复pip?

如何修复使用strtok后打印的乱码

如何在函数中增加全局变量,然后在 Python 中多次使用/增加

如何限制Android中后堆栈的大小?

排序限制后如何使用WITH ROLLUP

您知道如何使用 python 将文本文件中的每个单词复制多次吗?

如何在python中多次运行线程

如何在python中多次更新windowText?

如何多次使用下拉列表中的选项

如何在js中多次使用resize

如何使用python 3限制浮点数后的位数?

如何修复python中的“IndexError('切片停止%d超过%d'%(停止,长度))的限制”错误

使用for循环时如何修复某些测试用例中的“超出时间限制”?

删除python后如何修复未满足的依赖关系?

OSx更新后如何修复损坏的python 2.7.11

升级后如何修复ownCloud中损坏的JavaScript行为?

在android中构建后如何修复ArrayList的冗余

在AngularJS网页中滚动后如何修复元素

在C#中ComObject Release后如何修复excel?

使用create-react-app构建后如何修复白屏?

使用 nvidia 驱动程序启动后如何修复黑屏?

使用std :: cin函数后如何修复文件读取

如何使用 get 方法修复表单操作