This is an archival dump of old wiki content --- see for current material.
Please see


These modules are called "basic" because they are general and independant to all kind of data.

Before using a module, remind that you have to import it.

In general, if you want to change the color of an object, you have to type: = fg_color

where fg_color is a "tuple", say (0, 0, 0) for black.

Note: You can set color for each module/filter (when available, of course), as above. But you can also set background/foreground colors for all your MayaVi2 sessions. See Cookbook/MayaVi/Tips. So, your background and foreground colors may (in fact, must) be different from those in the pictures presented here.

Outline module

Nothing special for this very simple module.

Begin to import the Outline module:

from enthought.mayavi.modules.outline import Outline


fg_color = (0, 0, 0)    # black foreground color
o = Outline()
script.add_module(o) = fg_color


Axes module

For axis, you can set several parameters:

Here's what you can type:

from enthought.mayavi.modules.axes import Axes


a = Axes()
script.add_module(a) = fg_color                     # color for axes
a.axes.axis_title_text_property.color = fg_color     # color for axes title
a.axes.x_label = "Lx"                                # label for Ox axis
a.axes.y_label = "Ly"                                # label for Oy axis
a.axes.z_label = "Lz"                                # label for Oz axis
a.axes.label_format = ""                             # no dimensions displayed
a.axes.axis_label_text_property.color = fg_color     # in case we want to display them

Label format is the format for the dimensions along Ox, Oy and Oz axis. By default, it is set to %6.3g.


OrientationAxes module

OrientationAxes module will display a little trihedron in the corner of the render window, showing the orientation of the three axes, Ox, Oy, Oz.

Note: VTK > 5.0 must be installed in order to use this module.

Nothing special here, as the Outline module, you can set the labels color:

from enthought.mayavi.modules.orientation_axes import OrientationAxes


oa = OrientationAxes()
oa.text_property.color = fg_color


Text module

You can use this module to display a title for your rendering window.

You need a text (a string), and you have to set up its position in the window (coordinates go from 0 to 1 in x and y) with the x_position and y_position parameters.

Then you can set up the height and the width of your text:

from enthought.mayavi.modules.text import Text


# I like my title centered and at top of the window
t = Text()
t.text = "My Title Centered at the Top"
script.add_module(t) = False = 34 = fg_color
# have to find out text width to center it. Tricky, but works fine. Thanks to Prabhu.
t.width = 1.0*[0]
height = 1.0*[1]
t.x_position = 0.5-t.width/2
t.y_position = 1-height


Now, we will present how to set up the color bar, called "scalar" or "vector" color bar. It depends of the data you have in your file.

Setting up color bar

Strictly speaking, the color bar is not a module, i.e. you don't need to add it with an add_module() command: you have to associate the "module_manager" object to a module, previously loaded, say the Text module for example.

Then, you can configure the color bar as follows (keywords are self-explanatory):

mmsclut = t.module_manager.scalar_lut_manager
mmsclut.show_scalar_bar = True
mmsclutsc = mmsclut.scalar_bar
mmsclutsc.orientation = "vertical"    # or "horizontal"
mmsclutsc.width = 0.1
mmsclutsc.height = 0.8
mmsclutsc.position = (0.01, 0.15)     # color bar located to the left of the rendering window
mmsclutsc.label_text_property.color = fg_color
mmsclutsc.title_text_property.color = fg_color
mmsclut.number_of_labels = 10
mmsclut.number_of_colors = 64
mmsclut.data_name = "My Label"


Note: To configure a color bar for vectors instead of scalars, replace "scalar_lut_manager" by "vector_lut_manager" above.

At last, to close the "basic" modules section, let's see how we can setting up the scene.

Setting up the scene

By "setting up the scene", you have to read "how the scene will be seen": for example, setting the color background and the point of view of the scene.

As usual, setting these parameters using python & TVTK is very easy.

If you want to change background color, you may need to also change foreground color for all modules. We recall them here.

   1 #! /usr/bin/env python
   3 from enthought.mayavi.modules.outline import Outline
   4 from enthought.mayavi.modules.axes import Axes
   5 from enthought.mayavi.modules.orientation_axes import OrientationAxes
   6 from enthought.mayavi.modules.text import Text
   8 # we want a dark foreground color on a bright background
   9 fg_color = (0.06666, 0.06666, 0.1804)   # dark blue
  10 bg_color = (1, 1, 0.94118)              # ivory
  12 # setting foreground color for Outline module
  13 o = Outline()
  14 script.add_module(o)
  15 = fg_color
  17 # setting foreground color for Axes module
  18 a = Axes()
  19 script.add_module(a)
  20 = fg_color                     # color for axes
  21 a.axes.axis_title_text_property.color = fg_color     # color for axes label
  22 a.axes.x_label = "Lx"                                # label for Ox axis
  23 a.axes.y_label = "Ly"                                # label for Oy axis
  24 a.axes.z_label = "Lz"                                # label for Oz axis
  25 a.axes.label_format = ""                             # no dimensions displayed
  28 # setting foreground color for OrientationAxes module
  29 oa = OrientationAxes()
  30 script.add_module(oa)
  31 oa.text_property.color = fg_color
  33 # setting foreground color for Text module
  34 t = Text()
  35 t.text = "My Title Centered at the Top"
  36 script.add_module(t)
  37 = False
  38 = 34
  39 = fg_color
  40 t.width = 1.0*[0]
  41 height = 1.0*[1]
  42 t.x_position = 0.5-t.width/2
  43 t.y_position = 1-height
  45 # setting foreground color for labels and title color bar.
  46 mmsclut = t.module_manager.scalar_lut_manager
  47 mmsclut.show_scalar_bar = True
  48 mmsclutsc = mmsclut.scalar_bar
  49 mmsclutsc.orientation = "vertical"
  50 mmsclutsc.width = 0.1
  51 mmsclutsc.height = 0.8
  52 mmsclutsc.position = (0.01, 0.15)
  53 mmsclutsc.label_text_property.color = fg_color
  54 mmsclutsc.title_text_property.color = fg_color
  55 mmsclut.number_of_labels = 10
  56 mmsclut.number_of_colors = 64
  57 mmsclut.data_name = "My Label"
  59 # setting background color for the scene.
  60 t.scene.background = bg_color

Some points of view are also predefined in MayaVi2.

If you want:

You can also:



At last, you can choose if you want a perspective view or a parallel projection for your scene: = True


for a parallel projection, or: = False


for a perspective view.

Here, "t" stands for the Text module previously loaded.

Note: There are a lot of others parameters you can set up for your scene. See Cookbook/MayaVi/Tips to read how to get more information about setting parameters modules.

Now, it's time to read the most interesting part: configuring and using modules and filters which interact with your data.


SciPy: Cookbook/MayaVi/ScriptingMayavi2/BasicModules (last edited 2015-10-24 17:48:24 by anonymous)