mlabtex API

Purpose

mlabtex provides a renderer for latex code in mayavi.

Functions

The following functions are provided:

render_latex(text, path[, color, dpi, output]) Renders LaTeX-formula into an image.
mlabtex(x, y, z, text[, color, figure, …]) Render for matplotlib like text in mayavi.
mlabimg(x, y, z, path[, figure, name, …]) Render image files in mayavi.

mlabtex(x, y, z, text, color=(0, 0, 0), figure=None, name=None, opacity=1.0, orientation=(0.0, 0.0, 0.0), scale=1.0, dpi=1200)[source]

Render for matplotlib like text in mayavi. Analogous to mlab.text3d.

Parameters:
  • x (float) – x position of the text.
  • y (float) – y position of the text.
  • z (float) – z position of the text.
  • text (string) – The text is positionned in 3D, in figure coordinnates.
  • color (tuple, optional) – color of the text given as rgb tuple. Default: (0, 0, 0)
  • figure (Scene, optional) – Must be a Scene or None.
  • name (string, optional) – the name of the vtk object created.
  • opacity (float, optional) – The overall opacity of the vtk object. Must be a float. Default: 1.0
  • orientation (tuple, optional) – the angles giving the orientation of the text. If the text is oriented to the camera, these angles are referenced to the axis of the camera. If not, these angles are referenced to the z axis. Must be an array with shape (3,).
  • scale (float, optional) – The scale of the text, in figure units. It is rescaled by the size of the letter “I”.
  • dpi (int, optional) – Used dpi. Default: 1200
Returns:

surf – Mayavi Surf class with the rendered text as texture.

Return type:

Surf

Notes

If you get the following error:

RuntimeError: libpng signaled error

Try to set the dpi higher. (1200 recomended)

If big symbols like \int or \sum don’t show up properly, try setting a

\displaystyle

infront of them.

render_latex(text, path, color=(0, 0, 0), dpi=600, output='png')[source]

Renders LaTeX-formula into an image.

Parameters:
  • text (string) – String containing the latex-code.
  • path (string) – Path to the file to be saved.
  • color (tuple, optional) – color of the text given as rgb tuple. Default: (0, 0, 0)
  • dpi (int, optional) – Used dpi. Default: 1200
  • output (string, optional) – Output format. Default: "png"

Notes

If you get the following error:

RuntimeError: libpng signaled error

Try to set the dpi higher. (1200 recomended)

If big symbols like \int or \sum don’t show up properly, try setting a

\displaystyle

infront of them.

It will try to render it with sympy first. If that fails it will use matplotlib.

mlabimg(x, y, z, path, figure=None, name=None, opacity=1.0, orientation=(0.0, 0.0, 0.0), scale=1.0, typ=None, ref_y_extent=None)[source]

Render image files in mayavi. Analogous to mlab.text3d.

Parameters:
  • x (float) – x position of the text.
  • y (float) – y position of the text.
  • z (float) – z position of the text.
  • path (string) – Path to the image file.
  • color (tuple, optional) – color of the text given as rgb tuple. Default: (0, 0, 0)
  • figure (Scene, optional) – Must be a Scene or None.
  • name (string, optional) – the name of the vtk object created.
  • opacity (float, optional) – The overall opacity of the vtk object. Must be a float. Default: 1.0
  • orientation (tuple, optional) – the angles giving the orientation of the text. If the text is oriented to the camera, these angles are referenced to the axis of the camera. If not, these angles are referenced to the z axis. Must be an array with shape (3,).
  • scale (float, optional) – The vetical scale of the image, in figure units.
  • typ (string, optional) – Here you can specify the image type. Supported: ‘bmp’, ‘jpg’, ‘jpeg’, ‘png’, ‘pnm’, ‘dcm’, ‘tiff’, ‘ximg’, ‘dem’, ‘mha’, ‘mhd’, ‘mnc’. If set to None, the file type is determined by its extension. Default: None.
  • ref_y_extent (int, optional) – Reference vertical extent of the image to scale to. If set to None, the image extent itself is used. Default: None
Returns:

surf – Mayavi Surf class with the rendered image as texture.

Return type:

Surf