【发布时间】:2018-03-08 11:17:47
【问题描述】:
我目前想从我的 Walabot 设备中可视化 3D 原始数据,并将其显示在使用 matplotlib FuncAnimation 创建的 3D 动画中。我已经搜索了答案,但找不到任何有用的东西。 就我而言,我已经有一个 3 维数组,其中每个索引都有一个特定的值,该值会随着时间而变化。我已经可以弄清楚如何在具有不同颜色和大小的 3D 图表中显示它,但现在我想自己进行更新。我找到了一些示例代码,这些代码给了我一个良好的开端,但我的图表不会自行更新。我必须关闭窗口,然后窗口再次弹出,其中包含 3D 数组中的不同值。你们知道如何解决这个问题吗? 到目前为止,这是我的代码:
def update(plot, signal, figure):
plot.clear()
scatterplot = plot.scatter(x, y, z, zdir='z', s=signal[0], c=signal[0])
figure.show()
return figure
def calc_RasterImage(signal):
# 3D index is represnted is the following schema {i,j,k}
# sizeX - signal[1] represents the i dimension length
# sizeY - signal[2] represents the j dimension length
# sizeZ - signal[3] represents the k dimension length
# signal[0][i][j][k] - represents the walabot 3D scanned image (internal data)
#Initialize 3Dplot with matplotlib
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim([xMin-1,xMax-1])
ax.set_ylim([yMin-1,yMax-1])
ax.set_zlim([zMin-1,zMax-1])
ax.set_xlabel('X AXIS')
ax.set_ylabel('Y AXIS')
ax.set_zlabel('Z AXIS')
scatterplot = ax.scatter(x, y, z, zdir='z', s=signal[0], c= signal[0])
cbar = plt.colorbar(scatterplot)
cbar.set_label('Density')
#def update(signal):
# ax.clear()
# scatterplot = ax.scatter(x, y, z, zdir='z', s=signal[0], c=signal[0])
ani = anim.FuncAnimation(fig, update(ax, signal, plt), frames=10 , blit=True, repeat = True)
def main():
wlbt = Walabot()
wlbt.connect()
if not wlbt.isConnected:
print("Not Connected")
else:
print("Connected")
wlbt.start()
calc_index(wlbt.get_RawImage_values())
while True:
#print_RawImage_values(wlbt.get_RawImage_values())
calc_RasterImage(wlbt.get_RawImage_values())
wlbt.stop()
if __name__ == '__main__':
main()
正如你所看到的那样
ani = anim.FuncAnimation(fig, update(ax, signal, plt), frames=10 , blit=True, repeat = True)
需要顶部的更新功能。此函数清除我的绘图并重新创建具有不同值的新绘图。但我总是需要先关闭绘图窗口,这是我想避免的。 这是情节的样子: 3D array plot with matplotlib scatter 你们知道如何解决这个问题吗?
干杯
【问题讨论】:
标签: python arrays matplotlib 3d refresh