Mayavi mlab: set limits or mask out values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Mayavi mlab: set limits or mask out values

Mikkel Lepperød

I want to set my z-limits on a plot so I do not show the zero values. I hope someone can help me. The code is:

from __future__ import division
from pylab import *
from mayavi import mlab

k3 = lambda S, wD: S/2 - wD + sqrt(S**2 + 2*S - 4*wD + 1)/2 + 1/2

def threeD(func, a, b, c, d, cmaps, dist, xlab='S', ylab='w', zlab='K', cbshow=True, save=False):
    x = linspace(a, b, 100)
    y = linspace(c, d, 100)
    X, Y = meshgrid(x, y)
    mlab.figure(fgcolor=(0,0,0), bgcolor=(1,1,1), size = (900,768))
    Z = []
    for idx, cmap, zla in zip(range(len(func)),cmaps,zlab):
        Z.append(func[idx](X, Y).clip(min=0))
        surf =, Y, Z[idx], colormap=cmap, vmax=array(Z).max())

        mlab.axes(xlabel='%s'%xlab, ylabel='%s'%ylab, zlabel='%s'%zla)
    if cbshow:
    mlab.view(azimuth=10, elevation=80, distance=dist)
    Z = array(Z)
    if save:
        mlab.savefig(filename='%s.png'%save, magnification=1)

threeD([k4], -1.5, 1.5, 0, 1.5, zlab='K4', cmaps=['gist_rainbow'], save='3DK4', dist=6)

Enthought-Dev mailing list
[hidden email]