NDArray Plotter - Examples

Default Plotting


In [1]:
%pylab inline
import numpy as np
import ndap
reload(ndap)
subject = np.ones((5,5,5))
plotter = ndap.NDArrayPlotter(subject)
(fig, ax) = plotter.render()


Populating the interactive namespace from numpy and matplotlib

Changing the "camera"


In [2]:
(fig, ax) = plotter.render(azim=-45,elev=25)


Change color, and alpha


In [3]:
plotter.set_color("#FF0000")
plotter.set_alpha(1.0)

(fig, ax) = plotter.render(azim=-45,elev=25)


Selectively change colors, scale element-size and space between them


In [4]:
plotter.set_scale((0.01, 0.8, 0.8))
plotter.set_spacing(("l", 0.1, 1, 1)) # even = apply to all or apply as a function of l/m/n

colors = plotter.set_color("#00FF00")

colors[:,:,0] = "#FF0000"
colors[:,:,-1] = "#FF0000"
colors[0,:,:] = "#FF0000"
colors[-1,:,:] = "#FF0000"
colors[:,0,:] = "#FF0000"
colors[:,-1,:] = "#FF0000"

(fig_coord, ax_coors) = plotter.render()


Another example of selective coloring


In [5]:
subject = np.ones((1,5,5))
plotter = ndap.NDArrayPlotter(subject)

colors = plotter.set_color("#00FF00")

i = 1
colors[0,i,i]   = "#0000FF"
colors[0,i,i+1] = "#FF0000"
colors[0,i,i-1] = "#FF0000"
colors[0,i+1,i] = "#FF0000"
colors[0,i-1,i] = "#FF0000"

(fig, ax) = plotter.render()


Write element-labels, such as coordinates, values or whatever


In [6]:
subject = np.arange(0,9).reshape((1,3,3))
plotter = ndap.NDArrayPlotter(subject, alpha=0.2, spacing=("even", 0.1,0.1,0.1))

colors = plotter.set_color("#FFFF00")

colors[:,1,:] = "#FF0000"
colors[:,0,:] = "#00FF00"
colors[:,2,:] = "#0000FF"

Show coordinates


In [7]:
reload(ndap)
(fig_coord, ax_coors) = plotter.render(text=ndap.text_coords)


Show values


In [8]:
(fig_values, ax_value) = plotter.render(text=ndap.text_values)


Or something userdefined


In [9]:
def text_userdef(array, l, m, n):
    return "[%d,%d,%d] = %s" % (l, m, n, array[l,m,n])

plotter.set_scale((1.3,1.3,1.3))
(fig_values, ax_value) = plotter.render(text=text_userdef, azim=-10)



In [9]: