Search code examples
pythonmayavi

Mayavi: What does the scale_mode 'vector' do?


Can someone tell me what Mayavi's scale_mode = 'vector' is used for?

The various plotting functions all have the same sentence in their doc string:

scale_mode: the scaling mode for the glyphs (‘vector’, ‘scalar’, or ‘none’).

import numpy as np
from mayavi import mlab

o = np.array([0.0, 0.0, 0.0])
d = np.array([0.0, 0.0, 1.0])

mesh = mlab.quiver3d(o[0], o[1], o[2], d[0], d[1], d[2], scalars=2,
                                                         scale_mode='vector',
                                                         scale_factor=1.0)


mlab.axes(None, extent=[-1, 1, -1, 1, -1, 1])
mlab.gcf().scene.parallel_projection = True
mlab.show()

Solution

  • The scale mode in mayavi is passed directly to vtk, which may explain the difficulty to find documentation.

    In VTK, the option is passed down to a "glyph" (that is an object that is represented graphically), see the file vtkGlyph3D.cxx. For the mode "scale_by_vector", the magnitude of the vector data (only available for vector fields by default) is used to scale the glyph.

    Note that the scaling in mayavi is done with a reference unit that depends on your data (see the Mayavi documentation) unless the scale_factor option is given.