Mayavi in Sage

87 days ago by gvaroquaux

from enthought.mayavi import mlab #---------------------------------------------------------- # This is the key: make sure you set offscreen on up front mlab.options.offscreen = True #---------------------------------------------------------- mlab.test_contour3d() mlab.savefig('contour3d.png') 
       
# Example of the Lorenz attractor mlab.clf() import numpy as np def lorenz(x, y, z, s=10., r=28., b=8./3): """The Lorentz system.""" u = s*(y -x) v = r*x - y - x*z w = x*y - b*z return u, v, w x, y, z = np.mgrid[-50:50:100j, -50:50:100j, -10:60:70j] u, v, w = lorenz(x, y, z) fig = mlab.figure(size=(400, 400), bgcolor=(0, 0, 0)) # Plot tje flow of trajectories with suitable parameters. f = mlab.flow(x, y, z, u, v, w, line_width=3, colormap='Paired') f.module_manager.scalar_lut_manager.reverse_lut = True f.stream_tracer.integration_direction = 'both' f.stream_tracer.maximum_propagation = 200 # Hide the seed: f.seed.widget.enabled = False # A nice view of the plot mlab.view(140, 120, 140, [.65, 1.5, 27]) mlab.savefig('lorenz.png') 
       
# Test embedding x3d files. mlab.clf() mlab.figure() # A simple triangular mesh mlab.test_triangular_mesh() # Some nice vectors. x, y, z = np.mgrid[-2:3, -2:3, -2:3] r = np.sqrt(x**2 + y**2 + z**4) u = y * np.sin(r)/(r + .001) v = -x * np.sin(r)/(r + .001) w = np.zeros_like(z) mlab.quiver3d(x, y, z, u, v, w, scale_factor=1) # Export a x3d file for online 3D viewing # FreeWRL (http://freewrl.sourceforge.net) works great mlab.savefig("a.x3d")