Glyph exampleΒΆ

This script demonstrates using the Mayavi core API to add a VectorCutPlane, split the pipeline using a MaskPoints filter and then view the filtered data with the Glyph module.

Python source code:

# Author: Prabhu Ramachandran <>
# Copyright (c) 2005-2020, Enthought, Inc.
# License: BSD Style.

# Standard library imports
from os.path import join, abspath, dirname

# Enthought library imports
from mayavi.scripts import mayavi2
from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader
from mayavi.modules.outline import Outline
from mayavi.modules.glyph import Glyph
from mayavi.modules.vector_cut_plane import VectorCutPlane
from mayavi.filters.mask_points import MaskPoints

def glyph():
    """The script itself.  We needn't have defined a function but
    having a function makes this more reusable.
    # 'mayavi' is always defined on the interpreter.
    # Create a new VTK scene.

    # Read a VTK (old style) data file.
    r = VTKXMLFileReader()

    # Create an outline and a vector cut plane.

    v = VectorCutPlane()
    v.glyph.color_mode = 'color_by_scalar'

    # Now mask the points and show glyphs (we could also use
    # Vectors but glyphs are a bit more generic)
    m = MaskPoints()
    m.filter.trait_set(on_ratio=10, random_mode=True)

    g = Glyph()
    # Note that this adds the module to the filtered output.
    g.glyph.scale_mode = 'scale_by_vector'
    # Use arrows to view the scalars.
    gs = g.glyph.glyph_source
    gs.glyph_source = gs.glyph_dict['arrow_source']

if __name__ == '__main__':