python - 如何在python中多次使用ax.voxels方法后修复限制
问题描述
我正在使用从 Lidar 收到的 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()
它会导致体素位置显示的不良限制:
我希望所有组件都显示在正确的边界框中,如下所示:
或者,至少,这个(假设边界框也包括不可见的体素):
解决方案
我只能通过明确设置轴限制来完成这项工作:
# [...]
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()
推荐阅读
- perl - 在 Windows ActivePerl 上运行电子邮件程序时出现错误
- swift - Swift 如何监听 AWS DynamoDB 中的变化
- twilio - 如何使用 Twilo Studio 创建 Twilio 号码的扩展?
- javascript - 将对象中的数据提取到字符串表中
- c - 使用关闭的文件描述符阻止读取
- keras - 如何在 Conv2D 层之后添加 ConvLSTM2D 层?
- fullcalendar - 在 FullCalendar v4 中计算总时间
- android - 深层链接网址可以播放商店/应用商店,但如果安装则不打开应用
- c# - String.Join - 参数和直接值的不同行为
- java - 为什么我要使用 Lombok-Annotation @NonNull?