我需要可视化3D空间,并希望通过简单的滑动条导航Z维度。目前我只是通过破坏当前图像然后绘制下一个图像来迭代地显示Z平面中的每个堆栈。如何编辑以下简单示例以允许滑动条在Z方向上来回移动?
#!/usr/bin/env python
import sys
import numpy as np
import matplotlib.pylab as plt
if __name__=="__main__":
nx = 100
ny = 100
nz = 10
xs = np.linspace( -1, 1, nx )
ys = np.linspace( -1, 1, ny )
zs = np.linspace( -1, 1, nz )
A = np.zeros( (nx,ny,nz) )
for ix in range(nx):
x = xs[ix]
for iy in range(ny):
y = ys[iy]
for iz in range(nz):
z = zs[iz]
A[ix,iy,iz] = x*np.sin(z*x) + np.cos(z*y) + np.cos(z)
for iz in range(nz):
plt.matshow( A[:,:,iz] )
plt.show()