~ubuntu-branches/debian/sid/mayavi2/sid

« back to all changes in this revision

Viewing changes to docs/source/mayavi/auto/mlab_helper_functions.rst

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2009-03-27 04:34:55 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090327043455-vs6ox32daj6ndw33
Tags: 3.2.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
.. function:: imshow(*args, **kwargs)
20
20
 
21
21
    
22
 
    Allows one to view a 2D Numeric array as an image.  This works
23
 
    best for very large arrays (like 1024x1024 arrays).
 
22
    View a 2D array as an image.
24
23
    
25
24
    **Function signatures**::
26
25
    
27
 
        imshow(2darray, ...)
 
26
        imshow(s, ...)
 
27
    
 
28
    s is a 2 dimension array. The values of s are mapped to a color using
 
29
    the colormap.
28
30
    
29
31
    **Keyword arguments:**
30
32
    
40
42
    
41
43
        :figure: Figure to populate.
42
44
    
 
45
        :interpolate: if the pixels in the image are to be
 
46
                      interpolated or not. Must be a boolean. Default: True
 
47
    
43
48
        :line_width:  The with of the lines, if any used. Must be a float.
44
49
                     Default: 2.0
45
50
    
46
51
        :name: the name of the vtk object created.
47
52
    
48
 
        :opacity: The overall opacity of the vtk object. Must be a float.
49
 
                  Default: 1.0
50
 
    
51
 
        :representation: the representation type used for the surface. Must be
52
 
                         'surface' or 'wireframe' or 'points'. Default:
53
 
                         surface
 
53
        :opacity: the opacity of the image. Must be a legal value. Default:
 
54
                  1.0
54
55
    
55
56
        :transparent: make the opacity of the actor depend on the
56
57
                      scalar.
91
92
 
92
93
    
93
94
    Plots glyphs (like arrows) indicating the direction of the vectors
94
 
    for a 3D volume of data supplied as arguments.
 
95
    at the positions supplied.
95
96
    
96
97
    **Function signatures**::
97
98
    
99
100
        quiver3d(x, y, z, u, v, w, ...)
100
101
        quiver3d(x, y, z, f, ...)
101
102
    
102
 
    If only 3 arrays u, v, w are passed the x, y and z arrays are assumed to be
103
 
    made from the indices of vectors.
104
 
    
105
 
    If 4 positional arguments are passed the last one must be a callable, f,
106
 
    that returns vectors.
 
103
    u, v, w are numpy arrays giving the components of the vectors.
 
104
    
 
105
    If only 3 arrays, u, v, and w are passed, they must be 3D arrays, and
 
106
    the positions of the arrows are assumed to be the indices of the
 
107
    corresponding points in the (u, v, w) arrays.
 
108
    
 
109
    If 6 arrays, (x, y, z, u, v, w) are passed, the 3 first arrays give
 
110
    the position of the arrows, and the 3 last the components. They
 
111
    can be of any shape.
 
112
    
 
113
    If 4 positional arguments, (x, y, z, f) are passed, the last one must be
 
114
    a callable, f, that returns vectors components (u, v, w) given the
 
115
    positions (x, y, z).
107
116
    
108
117
    **Keyword arguments:**
109
118
    
144
153
    
145
154
        :scalars: optional scalar data.
146
155
    
147
 
        :scale_factor: the scaling applied to the glyphs. The
148
 
                       size of the glyph is by default in drawing
149
 
                       units. Must be a float. Default: 1.0
 
156
        :scale_factor: The scaling applied to the glyphs. the simple of the
 
157
                       glyph is by default calculated from the inter-glyph
 
158
                       spacing. Specify a float to give the maximum glyph size
 
159
                       in drawing units
150
160
    
151
161
        :scale_mode: the scaling mode for the glyphs
152
162
                     ('vector', 'scalar', or 'none').
174
184
    from enthought.mayavi.mlab import *
175
185
    
176
186
    def test_quiver3d():
177
 
        dims = [8, 8, 8]
178
 
        xmin, xmax, ymin, ymax, zmin, zmax = [-5,5,-5,5,-5,5]
179
 
        x, y, z = numpy.mgrid[xmin:xmax:dims[0]*1j,
180
 
                              ymin:ymax:dims[1]*1j,
181
 
                              zmin:zmax:dims[2]*1j]
182
 
        x = x.astype('f')
183
 
        y = y.astype('f')
184
 
        z = z.astype('f')
185
 
    
186
 
        sin = numpy.sin
187
 
        cos = numpy.cos
188
 
        u = cos(x)
189
 
        v = sin(y)
190
 
        w = sin(x*z)
191
 
    
192
 
        obj = quiver3d(x, y, z, u, v, w, mode='cone', extent=(0,1, 0,1, 0,1),
193
 
                       scale_factor=0.9)
194
 
    
 
187
        x, y, z = numpy.mgrid[-2:3, -2:3, -2:3]
 
188
        r = numpy.sqrt(x**2 + y**2 + z**4)
 
189
        u = y*numpy.sin(r)/(r+0.001)
 
190
        v = -x*numpy.sin(r)/(r+0.001)
 
191
        w = numpy.zeros_like(z)
 
192
        obj = quiver3d(x, y, z, u, v, w, line_width=3, scale_factor=1)
195
193
        return obj
196
194
    
197
195
                
211
209
        plot3d(x, y, z, ...)
212
210
        plot3d(x, y, z, s, ...)
213
211
    
 
212
    x, y, z and s are numpy arrays or lists of the same shape. x, y and z
 
213
    give the positions of the successive points of the line. s is an
 
214
    optional scalar value associated with each point.
 
215
    
214
216
    **Keyword arguments:**
215
217
    
216
218
        :color: the color of the vtk object. Overides the colormap,
270
272
        n_mer, n_long = 6, 11
271
273
        pi = numpy.pi
272
274
        dphi = pi/1000.0 
273
 
        phi = numpy.arange(0.0, 2*pi + 0.5*dphi, dphi, 'd')
 
275
        phi = numpy.arange(0.0, 2*pi + 0.5*dphi, dphi)
274
276
        mu = phi*n_mer
275
277
        x = numpy.cos(mu)*(1+numpy.cos(n_long*mu/n_mer)*0.5)
276
278
        y = numpy.sin(mu)*(1+numpy.cos(n_long*mu/n_mer)*0.5)
289
291
.. function:: surf(*args, **kwargs)
290
292
 
291
293
    
292
 
    Plots a surface using regularly spaced elevation data supplied as a 2D
 
294
    Plots a surface using regularly-spaced elevation data supplied as a 2D
293
295
    array.
294
296
    
295
297
    **Function signatures**::
298
300
        surf(x, y, s, ...)
299
301
        surf(x, y, f, ...)
300
302
    
301
 
    If 3 positional arguments are passed the last one must be an array s,
302
 
    or a callable, f, that returns an array. x and y give the
303
 
    coordinnates of positions corresponding to the s values.
304
 
    
305
 
    z is the elevation matrix.
 
303
    s is the elevation matrix, a 2D array.
306
304
    
307
305
    x and y can be 1D or 2D arrays (such as returned by numpy.ogrid or
308
306
    numpy.mgrid), but the points should be located on an orthogonal grid
311
309
    arbitrary-shaped position arrays (non-orthogonal grids), see the mesh
312
310
    function.
313
311
    
314
 
    If only 1 array s is passed the x and y arrays are assumed to be
 
312
    If only 1 array s is passed, the x and y arrays are assumed to be
315
313
    made from the indices of arrays, and an uniformly-spaced data set is
316
314
    created.
317
315
    
 
316
    If 3 positional arguments are passed the last one must be an array s,
 
317
    or a callable, f, that returns an array. x and y give the
 
318
    coordinnates of positions corresponding to the s values.
 
319
    
318
320
    **Keyword arguments:**
319
321
    
320
322
        :color: the color of the vtk object. Overides the colormap,
406
408
    
407
409
        mesh(x, y, z, ...)
408
410
    
409
 
    x, y, z are 2D arrays giving the positions of the vertices of the surface.
410
 
    The connectivity between these points is implied by the connectivity on
411
 
    the arrays.
 
411
    x, y, z are 2D arrays, all of the same shape, giving the positions of
 
412
    the vertices of the surface. The connectivity between these points is
 
413
    implied by the connectivity on the arrays.
412
414
    
413
415
    For simple structures (such as orthogonal grids) prefer the surf function,
414
416
    as it will create more efficient data structures.
415
417
    
416
 
    
417
418
    **Keyword arguments:**
418
419
    
419
420
        :color: the color of the vtk object. Overides the colormap,
525
526
    **Function signatures**::
526
527
    
527
528
        contour3d(scalars, ...)
528
 
        contour3d(scalarfield, ...)
 
529
        contour3d(x, y, z, scalars, ...)
 
530
    
 
531
    scalars is a 3D numpy arrays giving the data on a grid.
 
532
    
 
533
    If 4 arrays, (x, y, z, scalars) are passed, the 3 first arrays give
 
534
    the position of the arrows, and the last the scalar value. The x, y
 
535
    and z arrays are then supposed to have been generated by
 
536
    `numpy.mgrid`, in other words, they are 3D arrays, with positions
 
537
    lying on a 3D orthogonal and regularily spaced grid with nearest
 
538
    neighboor in space matching nearest neighboor in the array. The
 
539
    function builds a scalar field assuming  the points are regularily
 
540
    spaced.
 
541
    
 
542
    If 4 positional arguments, (x, y, z, f) are passed, the last one
 
543
    can also be a callable, f, that returns vectors components (u, v, w)
 
544
    given the positions (x, y, z).
529
545
    
530
546
    **Keyword arguments:**
531
547
    
577
593
    from enthought.mayavi.mlab import *
578
594
    
579
595
    def test_contour3d():
580
 
        dims = [64, 64, 64]
581
 
        xmin, xmax, ymin, ymax, zmin, zmax = [-5,5,-5,5,-5,5]
582
 
        x, y, z = numpy.ogrid[xmin:xmax:dims[0]*1j,
583
 
                              ymin:ymax:dims[1]*1j,
584
 
                              zmin:zmax:dims[2]*1j]
585
 
        x = x.astype('f')
586
 
        y = y.astype('f')
587
 
        z = z.astype('f')
588
 
    
589
 
        sin = numpy.sin
 
596
        x, y, z = numpy.ogrid[-5:5:64j, -5:5:64j, -5:5:64j]
 
597
        
590
598
        scalars = x*x*0.5 + y*y + z*z*2.0
591
599
    
592
600
        obj = contour3d(scalars, contours=4, transparent=True)
606
614
    
607
615
    **Function signatures**::
608
616
    
609
 
        points3d(scalardata, ...)
610
617
        points3d(x, y, z...)
611
618
        points3d(x, y, z, s, ...)
612
619
        points3d(x, y, z, f, ...)
613
620
    
614
 
    If only one positional argument is passed, it should be VTK data
615
 
    object with scalar data.
616
 
    
617
 
    If only 3 arrays x, y, z all the points are drawn with the same size
618
 
    and color
619
 
    
620
 
    If 4 positional arguments are passed the last one can be an array s
621
 
    or a callable f that gives the size and color of the glyph.
 
621
    x, y and z are numpy arrays, or lists, all of the same shape, giving
 
622
    the positions of the points.
 
623
    
 
624
    If only 3 arrays x, y, z are given, all the points are drawn with the
 
625
    same size and color.
 
626
    
 
627
    In addition, you can pass a fourth array s of the same
 
628
    shape as x, y, and z giving an associated scalar value for each
 
629
    point, or a function f(x, y, z) returning the scalar value. This
 
630
    scalar value can be used to modulate the color and the size of the
 
631
    points.
622
632
    
623
633
    **Keyword arguments:**
624
634
    
657
667
                     instance, this is the number of divisions along theta and
658
668
                     phi. Must be an integer. Default: 8
659
669
    
660
 
        :scale_factor: the scaling applied to the glyphs. The
661
 
                       size of the glyph is by default in drawing
662
 
                       units. Must be a float. Default: 1.0
 
670
        :scale_factor: The scaling applied to the glyphs. the simple of the
 
671
                       glyph is by default calculated from the inter-glyph
 
672
                       spacing. Specify a float to give the maximum glyph size
 
673
                       in drawing units
663
674
    
664
675
        :scale_mode: the scaling mode for the glyphs
665
676
                     ('vector', 'scalar', or 'none').
708
719
.. function:: flow(*args, **kwargs)
709
720
 
710
721
    
711
 
    Creates streamlines following the flow of a vector field.
 
722
    Creates trajectories of particles following the flow of a vector field.
712
723
    
713
724
    **Function signatures**::
714
725
    
716
727
        flow(x, y, z, u, v, w, ...)
717
728
        flow(x, y, z, f, ...)
718
729
    
719
 
    If only 3 arrays u, v, w are passed the x, y and z arrays are assumed to be
720
 
    made from the indices of vectors.
721
 
    
722
 
    If the x, y and z arrays are passed they are supposed to have been
723
 
    generated by `numpy.mgrid`. The function builds a scalar field assuming
724
 
    the points are regularily spaced.
725
 
    
726
 
    If 4 positional arguments are passed the last one must be a callable, f,
727
 
    that returns vectors.
 
730
    u, v, w are numpy arrays giving the components of the vectors.
 
731
    
 
732
    If only 3 arrays, u, v, and w are passed, they must be 3D arrays, and
 
733
    the positions of the arrows are assumed to be the indices of the
 
734
    corresponding points in the (u, v, w) arrays.
 
735
    
 
736
    If 6 arrays, (x, y, z, u, v, w) are passed, the 3 first arrays give
 
737
    the position of the arrows, and the 3 last the components. The x, y
 
738
    and z arrays are then supposed to have been generated by
 
739
    `numpy.mgrid`, in other words, they are 3D arrays, with positions
 
740
    lying on a 3D orthogonal and regularily spaced grid with nearest
 
741
    neighboor in space matching nearest neighboor in the array. The
 
742
    function builds a vector field assuming  the points are regularily
 
743
    spaced.
 
744
    
 
745
    If 4 positional arguments, (x, y, z, f) are passed, the last one must be
 
746
    a callable, f, that returns vectors components (u, v, w) given the
 
747
    positions (x, y, z).
728
748
    
729
749
    **Keyword arguments:**
730
750
    
793
813
    from enthought.mayavi.mlab import *
794
814
    
795
815
    def test_flow():
796
 
        dims = [32, 32, 32]
797
 
        xmin, xmax, ymin, ymax, zmin, zmax = [-5,5,-5,5,-5,5]
798
 
        x, y, z = numpy.mgrid[xmin:xmax:dims[0]*1j,
799
 
                              ymin:ymax:dims[1]*1j,
800
 
                              zmin:zmax:dims[2]*1j]
801
 
        x = x.astype('f')
802
 
        y = y.astype('f')
803
 
        z = z.astype('f')
804
 
    
805
 
        sin = numpy.sin
806
 
        cos = numpy.cos
807
 
        u = cos(x/2.)
808
 
        v = sin(y/2.)
809
 
        w = sin(x*z/4.)
810
 
    
811
 
        obj = flow(x, y, z, u, v, w, linetype='tube')
 
816
        x, y, z = numpy.mgrid[0:5, 0:5, 0:5]
 
817
        r = numpy.sqrt(x**2 + y**2 + z**4)
 
818
        u = y*numpy.sin(r)/r
 
819
        v = -x*numpy.sin(r)/r
 
820
        w = numpy.zeros_like(z)
 
821
        obj = flow(u, v, w)
812
822
        return obj
813
823
    
814
824
                
821
831
.. function:: contour_surf(*args, **kwargs)
822
832
 
823
833
    
824
 
    Plots a the contours of asurface using grid spaced data supplied as 2D
825
 
    arrays.
 
834
    Plots a the contours of a surface using grid-spaced data for
 
835
    elevation supplied as a 2D array.
826
836
    
827
837
    **Function signatures**::
828
838
    
830
840
        contour_surf(x, y, s, ...)
831
841
        contour_surf(x, y, f, ...)
832
842
    
833
 
    If only one array s is passed the x and y arrays are assumed to be made
834
 
    of the indices of s.
835
 
    s is the elevation matrix.
 
843
    s is the elevation matrix, a 2D array. The contour lines plotted
 
844
    are lines of equal s value.
 
845
    
 
846
    x and y can be 1D or 2D arrays (such as returned by numpy.ogrid or
 
847
    numpy.mgrid), but the points should be located on an orthogonal grid
 
848
    (possibly non-uniform). In other words, all the points sharing a same
 
849
    index in the s array need to have the same x or y value. For
 
850
    arbitrary-shaped position arrays (non-orthogonal grids), see the mesh
 
851
    function.
 
852
    
 
853
    If only 1 array s is passed, the x and y arrays are assumed to be
 
854
    made from the indices of arrays, and an uniformly-spaced data set is
 
855
    created.
 
856
    
 
857
    If 3 positional arguments are passed the last one must be an array s,
 
858
    or a callable, f, that returns an array. x and y give the
 
859
    coordinnates of positions corresponding to the s values.
836
860
    
837
861
    **Keyword arguments:**
838
862
    
909
933
    histogram-like plots.
910
934
    
911
935
    This functions accepts a wide variety of inputs, with positions given
912
 
    in 2D or in 3D.
 
936
    in 2-D or in 3-D.
913
937
    
914
938
    **Function signatures**::
915
939
    
919
943
        barchart(x, y, z, s, ...)
920
944
        barchart(x, y, z, f, ...)
921
945
    
922
 
    If only one positional argument is passed, it can be a 1D, 2D, or 3D
 
946
    If only one positional argument is passed, it can be a 1-D, 2-D, or 3-D
923
947
    array giving the length of the vectors. The positions of the data
924
948
    points are deducted from the indices of array, and an
925
949
    uniformly-spaced data set is created.
1023
1047
    
1024
1048
    **Function signatures**::
1025
1049
    
1026
 
        mesh(x, y, z, triangles ...)
 
1050
        triangular_mesh(x, y, z, triangles ...)
1027
1051
    
1028
1052
    x, y, z are arrays giving the positions of the vertices of the surface.
1029
1053
    triangles is a list of triplets (or an array) list the vertices in
1119
1143
            triangles.
1120
1144
        """
1121
1145
        n = 8
1122
 
        t = numpy.linspace(0, 2*numpy.pi, n)
 
1146
        t = numpy.linspace(-numpy.pi, numpy.pi, n)
1123
1147
        z = numpy.exp(1j*t)
1124
1148
        x = z.real.copy()
1125
1149
        y = z.imag.copy()