我目前想从我的Walabot设备中可视化3D原始数据,并将其显示在使用matplotlib FuncAnimation创建的3D动画中。我已经找到了答案,但没有找到任何有用的。
在我的例子中,我已经有了一个三维数组,其中每个索引都有一个特定的值,该值随时间而变化。我已经知道如何在不同颜色和大小的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