~ubuntu-branches/ubuntu/trusty/mayavi2/trusty

« back to all changes in this revision

Viewing changes to mayavi/mlab.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-09 01:18:36 UTC
  • mfrom: (1.1.10 upstream) (2.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110709011836-fha21zirlgkqh92s
Tags: 4.0.0-1
* New upstream release
* debian/control:
  - Bump Standards-Version to 3.9.2
  - Set X-Python-Version: 2.6, fixes FTBFS (Closes: #625148)
  - Update Depends
* Update debian/watch file
* Cleanup debian/rules file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
mlab: a simple scripting interface to Mayavi2 for 3D plotting.
 
3
 
 
4
Can be used inside Mayavi2 itself, in "ipython -wthread", or in any
 
5
application with the WxWidget mainloop running.
 
6
"""
 
7
 
 
8
# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>
 
9
#         Gael Varoquaux <gael dot varoquaux at normalesup dot org>
 
10
# Copyright (c) 2007-2010, Enthought, Inc.
 
11
# License: BSD Style.
 
12
 
 
13
 
 
14
# Try forcing the use of wx 2.8 before any other import.
 
15
import sys
 
16
if not 'wx' in sys.modules:
 
17
    try:
 
18
        from traits.etsconfig.api import ETSConfig
 
19
        if ETSConfig.toolkit in ('wx', ''):
 
20
            import wxversion
 
21
            wxversion.ensureMinimal('2.8')
 
22
    except ImportError:
 
23
        """ wxversion not installed """
 
24
 
 
25
 
 
26
# Mayavi imports
 
27
from mayavi.tools.camera import view, roll, yaw, pitch, move
 
28
from mayavi.tools.figure import figure, clf, gcf, savefig, \
 
29
    draw, sync_camera, close, screenshot
 
30
from mayavi.tools.engine_manager import get_engine, show_pipeline, \
 
31
        options, set_engine
 
32
from mayavi.tools.show import show
 
33
from mayavi.tools.animator import animate
 
34
 
 
35
def show_engine():
 
36
    """ This function is deprecated, please use show_pipeline.
 
37
    """
 
38
    import warnings
 
39
    warnings.warn('The show_engine function is deprecated, please use'
 
40
                    'show_pipeline', stacklevel=2)
 
41
    return show_pipeline()
 
42
 
 
43
from tools.helper_functions import contour3d, test_contour3d, \
 
44
    quiver3d, test_quiver3d, test_quiver3d_2d_data, \
 
45
    points3d, test_points3d, test_molecule, \
 
46
    flow, test_flow, \
 
47
    imshow, test_imshow, \
 
48
    surf, test_surf, mesh, test_mesh, test_simple_surf, \
 
49
    test_mesh_sphere, test_fancy_mesh,\
 
50
    contour_surf, test_contour_surf, \
 
51
    plot3d, test_plot3d, \
 
52
    test_plot3d_anim, test_points3d_anim, test_contour3d_anim,\
 
53
    test_simple_surf_anim, test_flow_anim, test_mesh_sphere_anim, \
 
54
    triangular_mesh, test_triangular_mesh, barchart, \
 
55
    test_barchart
 
56
 
 
57
 
 
58
from tools.decorations import colorbar, scalarbar, vectorbar, \
 
59
    outline, axes, xlabel, ylabel, zlabel, text, title, \
 
60
    orientation_axes, text3d
 
61
 
 
62
import tools.pipeline as pipeline
 
63
 
 
64
from tools.tools import start_recording, stop_recording
 
65
 
 
66
if __name__ == "__main__":
 
67
    import numpy
 
68
 
 
69
    n_mer, n_long = 6, 11
 
70
    pi = numpy.pi
 
71
    dphi = pi/1000.0
 
72
    phi = numpy.arange(0.0, 2*pi + 0.5*dphi, dphi, 'd')
 
73
    mu = phi*n_mer
 
74
    x = numpy.cos(mu)*(1+numpy.cos(n_long*mu/n_mer)*0.5)
 
75
    y = numpy.sin(mu)*(1+numpy.cos(n_long*mu/n_mer)*0.5)
 
76
    z = numpy.sin(n_long*mu/n_mer)*0.5
 
77
 
 
78
    pl = plot3d(x, y, z, numpy.sin(mu), tube_radius=0.05, colormap='Spectral')
 
79
 
 
80
    colorbar(orientation='vertical')
 
81
 
 
82
    t = numpy.linspace(0, 4*numpy.pi, 100)
 
83
    cos = numpy.cos
 
84
    sin = numpy.sin
 
85
 
 
86
    x = sin(2*t)
 
87
    y = cos(t)
 
88
    z = sin(2*t)
 
89
    s = sin(t)
 
90
 
 
91
    pts = points3d(x, y, z, s, colormap="YlGnBu", scale_factor=0.1,
 
92
            extent=(-0.3,0.3, -0.3, 0.3, -0.2,0.2))
 
93
 
 
94
    axes(xlabel='X', ylabel='Y', zlabel='Z')
 
95
    outline(pl)
 
96
 
 
97
    title('Mayavi rocks', height=0.85)
 
98