1

I need to visualize a 3D space and would like to navigate the Z dimension by a simple slidebar. Currently I just iteratively show each stack in the Z plane by destroying the current image and then plotting the next. How can I edit the below simple example to allow for a slidebar to go back and forth in the Z direction?

#!/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()
drjrm3
  • 4,474
  • 10
  • 53
  • 91

0 Answers0