W3cubDocs

/Matplotlib 3.5

matplotlib.texmanager

Support for embedded TeX expressions in Matplotlib.

Requirements:

  • LaTeX.
  • *Agg backends: dvipng>=1.6.
  • PS backend: PSfrag, dvips, and Ghostscript>=9.0.
  • PDF and SVG backends: if LuaTeX is present, it will be used to speed up some post-processing steps, but note that it is not used to parse the TeX string itself (only LaTeX is supported).

To enable TeX rendering of all text in your Matplotlib figure, set rcParams["text.usetex"] (default: False) to True.

TeX and dvipng/dvips processing results are cached in ~/.matplotlib/tex.cache for reuse between sessions.

TexManager.get_rgba can also be used to directly obtain raster output as RGBA NumPy arrays.

classmatplotlib.texmanager.TexManager[source]

Bases: object

Convert strings to dvi files using TeX, caching the results to a directory.

Repeated calls to this constructor always return the same instance.

propertyfont_families[source]
propertyfont_family[source]
propertyfont_info[source]
get_basefile(tex, fontsize, dpi=None)[source]

Return a filename based on a hash of the string, fontsize, and dpi.

get_custom_preamble()[source]

Return a string containing user additions to the tex preamble.

get_font_config()[source]
get_font_preamble()[source]

Return a string containing font configuration for the tex preamble.

get_grey(tex, fontsize=None, dpi=None)[source]

Return the alpha channel.

get_rgba(tex, fontsize=None, dpi=None, rgb=(0, 0, 0))[source]

Return latex's rendering of the tex string as an rgba array.

Examples

>>> texmanager = TexManager()
>>> s = r"\TeX\ is $\displaystyle\sum_n\frac{-e^{i\pi}}{2^n}$!"
>>> Z = texmanager.get_rgba(s, fontsize=12, dpi=80, rgb=(1, 0, 0))
get_text_width_height_descent(tex, fontsize, renderer=None)[source]

Return width, height and descent of the text.

propertygrey_arrayd[source]
make_dvi(tex, fontsize)[source]

Generate a dvi file containing latex's layout of tex string.

Return the file name.

make_png(tex, fontsize, dpi)[source]

Generate a png file containing latex's rendering of tex string.

Return the file name.

make_tex(tex, fontsize)[source]

Generate a tex file to render the tex string at a specific font size.

Return the file name.

texcache='/home/elliott/.cache/matplotlib/tex.cache'

© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/texmanager_api.html