matplotlib.mathtext#

Inheritance diagram of matplotlib.mathtext

A module for parsing a subset of the TeX math syntax and rendering it to aMatplotlib backend.

For a tutorial of its usage, seeWriting mathematical expressions. Thisdocument is primarily concerned with implementation details.

The module usespyparsing to parse the TeX expression.

The Bakoma distribution of the TeX Computer Modern fonts, and STIXfonts are supported. There is experimental support for usingarbitrary fonts, but results may vary without proper tweaking andmetrics for those fonts.

classmatplotlib.mathtext.MathTextParser(output)[source]#

Bases:object

Create a MathTextParser for the given backendoutput.

Parameters:
output{"path", "agg"}

Whether to return aVectorParse ("path") or aRasterParse ("agg", or its synonym "macosx").

parse(s,dpi=72,prop=None,*,antialiased=None)[source]#

Parse the given math expressions at the givendpi. Ifprop isprovided, it is aFontProperties object specifying the "default"font to use in the math expression, used for all non-math text.

The results are cached, so multiple calls toparsewith the same expression should be fast.

Depending on theoutput type, this returns either aVectorParse oraRasterParse.

classmatplotlib.mathtext.RasterParse(ox,oy,width,height,depth,image)[source]#

Bases:NamedTuple

The namedtuple type returned byMathTextParser("agg").parse(...).

Attributes:
ox, oyfloat

The offsets are always zero.

width, height, depthfloat

The global metrics.

image2D array of uint8

A raster image.

Create new instance of RasterParse(ox, oy, width, height, depth, image)

depth#

Alias for field number 4

height#

Alias for field number 3

image#

Alias for field number 5

ox#

Alias for field number 0

oy#

Alias for field number 1

width#

Alias for field number 2

classmatplotlib.mathtext.VectorParse(width,height,depth,glyphs,rects)[source]#

Bases:NamedTuple

The namedtuple type returned byMathTextParser("path").parse(...).

Attributes:
width, height, depthfloat

The global metrics.

glyphslist

The glyphs including their positions.

rectlist

The list of rectangles.

Create new instance of VectorParse(width, height, depth, glyphs, rects)

depth#

Alias for field number 2

glyphs#

Alias for field number 3

height#

Alias for field number 1

rects#

Alias for field number 4

width#

Alias for field number 0

matplotlib.mathtext.get_unicode_index(symbol)[source]#

Return the integer index (from the Unicode table) ofsymbol.

Parameters:
symbolstr

A single (Unicode) character, a TeX command (e.g. r'pi') or a Type1symbol name (e.g. 'phi').

matplotlib.mathtext.math_to_image(s,filename_or_obj,prop=None,dpi=None,format=None,*,color=None)[source]#

Given a math expression, renders it in a closely-clipped boundingbox to an image file.

Parameters:
sstr

A math expression. The math portion must be enclosed in dollar signs.

filename_or_objstr or path-like or file-like

Where to write the image data.

propFontProperties, optional

The size and style of the text.

dpifloat, optional

The output dpi. If not set, the dpi is determined as forFigure.savefig.

formatstr, optional

The output format, e.g., 'svg', 'pdf', 'ps' or 'png'. If not set, theformat is determined as forFigure.savefig.

colorstr, optional

Foreground color, defaults torcParams["text.color"] (default:'black').