# matplotlib.mathtext¶

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

For a tutorial of its usage, see Writing mathematical expressions. This document is primarily concerned with implementation details.

The module uses pyparsing to parse the TeX expression.

The Bakoma distribution of the TeX Computer Modern fonts, and STIX fonts are supported. There is experimental support for using arbitrary fonts, but results may vary without proper tweaking and metrics for those fonts.

class matplotlib.mathtext.Accent(c, state, math=True)[source]

Bases: matplotlib.mathtext.Char

The font metrics need to be dealt with differently for accents, since they are already offset correctly from the baseline in TrueType fonts.

grow(self)[source]

Grows one level larger. There is no limit to how big something can get.

render(self, x, y)[source]

Render the character to the canvas.

shrink(self)[source]

Shrinks one level smaller. There are only three levels of sizes, after which things will no longer get smaller.

class matplotlib.mathtext.AutoHeightChar(c, height, depth, state, always=False, factor=None)[source]

A character as close to the given height and depth as possible.

When using a font with multiple height versions of some characters (such as the BaKoMa fonts), the correct glyph will be selected, otherwise this will always just return a scaled version of the glyph.

class matplotlib.mathtext.AutoWidthChar(c, width, state, always=False, char_class=<class 'matplotlib.mathtext.Char'>)[source]

A character as close to the given width as possible.

When using a font with multiple width versions of some characters (such as the BaKoMa fonts), the correct glyph will be selected, otherwise this will always just return a scaled version of the glyph.

class matplotlib.mathtext.BakomaFonts(*args, **kwargs)[source]

Use the Bakoma TrueType fonts for rendering.

Symbols are strewn about a number of font files, each of which has its own proprietary 8-bit encoding.

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
alias = '\\]'
get_sized_alternatives_for_symbol(self, fontname, sym)[source]

Override if your font provides multiple sizes of the same symbol. Should return a list of symbols matching sym in various sizes. The expression renderer will select the most appropriate size for a given situation from this list.

target = ']'
class matplotlib.mathtext.Box(width, height, depth)[source]

Bases: matplotlib.mathtext.Node

A node with a physical location.

grow(self)[source]

Grows one level larger. There is no limit to how big something can get.

render(self, x1, y1, x2, y2)[source]
shrink(self)[source]

Shrinks one level smaller. There are only three levels of sizes, after which things will no longer get smaller.

class matplotlib.mathtext.Char(c, state, math=True)[source]

Bases: matplotlib.mathtext.Node

A single character.

Unlike TeX, the font information and metrics are stored with each Char to make it easier to lookup the font metrics when needed. Note that TeX boxes have a width, height, and depth, unlike Type1 and TrueType which use a full bounding box and an advance in the x-direction. The metrics must be converted to the TeX model, and the advance (if different from width) must be converted into a Kern node when the Char is added to its parent Hlist.

get_kerning(self, next)[source]

Return the amount of kerning between this and the given character.

This method is called when characters are strung together into Hlist to create Kern nodes.

grow(self)[source]

Grows one level larger. There is no limit to how big something can get.

is_slanted(self)[source]
render(self, x, y)[source]

Render the character to the canvas

shrink(self)[source]

Shrinks one level smaller. There are only three levels of sizes, after which things will no longer get smaller.

class matplotlib.mathtext.ComputerModernFontConstants[source]
delta = 0.075
delta_integral = 0.3
delta_slanted = 0.3
script_space = 0.075
sub1 = 0.2
sub2 = 0.3
subdrop = 0.2
sup1 = 0.45
class matplotlib.mathtext.DejaVuFonts(*args, **kwargs)[source]
Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
use_cmex = False
class matplotlib.mathtext.DejaVuSansFontConstants[source]
class matplotlib.mathtext.DejaVuSansFonts(*args, **kwargs)[source]

A font handling class for the DejaVu Sans fonts

If a glyph is not found it will fallback to Stix Sans

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
class matplotlib.mathtext.DejaVuSerifFontConstants[source]
class matplotlib.mathtext.DejaVuSerifFonts(*args, **kwargs)[source]

A font handling class for the DejaVu Serif fonts

If a glyph is not found it will fallback to Stix Serif

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
matplotlib.mathtext.Error(msg)[source]

Helper class to raise parser errors.

class matplotlib.mathtext.Fil(**kwargs)[source]

Bases: matplotlib.mathtext.Glue

[Deprecated]

Notes

Deprecated since version 3.3:

class matplotlib.mathtext.Fill(**kwargs)[source]

Bases: matplotlib.mathtext.Glue

[Deprecated]

Notes

Deprecated since version 3.3:

class matplotlib.mathtext.Filll(**kwargs)[source]

Bases: matplotlib.mathtext.Glue

[Deprecated]

Notes

Deprecated since version 3.3:

class matplotlib.mathtext.FontConstantsBase[source]

Bases: object

A set of constants that controls how certain things, such as sub- and superscripts are laid out. These are all metrics that can't be reliably retrieved from the font metrics in the font itself.

delta = 0.025
delta_integral = 0.1
delta_slanted = 0.2
script_space = 0.05
sub1 = 0.3
sub2 = 0.5
subdrop = 0.4
sup1 = 0.7
class matplotlib.mathtext.Fonts(default_font_prop, mathtext_backend)[source]

Bases: object

An abstract base class for a system of fonts to use for mathtext.

The class must be able to take symbol keys and font file names and return the character metrics. It also delegates to a backend class to do the actual drawing.

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
destroy(self)[source]

Fix any cyclical references before the object is about to be destroyed.

get_kern(self, font1, fontclass1, sym1, fontsize1, font2, fontclass2, sym2, fontsize2, dpi)[source]

Get the kerning distance for font between sym1 and sym2.

fontX: one of the TeX font names:

tt, it, rm, cal, sf, bf or default/regular (non-math)

fontclassX: TODO

symX: a symbol in raw TeX form. e.g., '1', 'x' or 'sigma'

fontsizeX: the fontsize in points

dpi: the current dots-per-inch

get_metrics(self, font, font_class, sym, fontsize, dpi, math=True)[source]

font: one of the TeX font names:

tt, it, rm, cal, sf, bf or default/regular (non-math)

font_class: TODO

sym: a symbol in raw TeX form. e.g., '1', 'x' or 'sigma'

fontsize: font size in points

dpi: current dots-per-inch

math: whether sym is a math character

Returns an object with the following attributes:

• height: The height of the glyph in points.
• width: The width of the glyph in points.
• xmin, xmax, ymin, ymax - the ink rectangle of the glyph
• iceberg - the distance from the baseline to the top of the glyph. This corresponds to TeX's definition of "height".
get_results(self, box)[source]

Get the data needed by the backend to render the math expression. The return value is backend-specific.

get_sized_alternatives_for_symbol(self, fontname, sym)[source]

Override if your font provides multiple sizes of the same symbol. Should return a list of symbols matching sym in various sizes. The expression renderer will select the most appropriate size for a given situation from this list.

get_underline_thickness(self, font, fontsize, dpi)[source]

Get the line thickness that matches the given font. Used as a base unit for drawing lines such as in a fraction or radical.

get_used_characters(self)[source]

Get the set of characters that were used in the math expression. Used by backends that need to subset fonts so they know which glyphs to include.

get_xheight(self, font, fontsize, dpi)[source]

Get the xheight for the given font and fontsize.

render_glyph(self, ox, oy, facename, font_class, sym, fontsize, dpi)[source]

Draw a glyph at

• ox, oy: position
• facename: One of the TeX face names
• font_class:
• sym: TeX symbol name or single character
• fontsize: fontsize in points
• dpi: The dpi to draw at.
render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled rectangle from (x1, y1) to (x2, y2).

set_canvas_size(self, w, h, d)[source]

Set the size of the buffer used to render the math expression. Only really necessary for the bitmap backends.

class matplotlib.mathtext.Glue(glue_type, copy=<deprecated parameter>)[source]

Bases: matplotlib.mathtext.Node

Most of the information in this object is stored in the underlying _GlueSpec class, which is shared between multiple glue objects. (This is a memory optimization which probably doesn't matter anymore, but it's easier to stick to what TeX does.)

property glue_subtype
grow(self)[source]

Grows one level larger. There is no limit to how big something can get.

shrink(self)[source]

Shrinks one level smaller. There are only three levels of sizes, after which things will no longer get smaller.

class matplotlib.mathtext.GlueSpec(**kwargs)[source]

Bases: object

[Deprecated] See Glue.

Notes

Deprecated since version 3.3.

copy(self)[source]
classmethod factory(glue_type)[source]
class matplotlib.mathtext.HCentered(elements)[source]

A convenience class to create an Hlist whose contents are centered within its enclosing box.

class matplotlib.mathtext.Hbox(width)[source]

Bases: matplotlib.mathtext.Box

A box with only width (zero height and depth).

Bases: matplotlib.mathtext.List

A horizontal list of boxes.

Compute the dimensions of the resulting boxes, and adjust the glue if one of those dimensions is pre-specified. The computed sizes normally enclose all of the material inside the new box; but some items may stick out if negative glue is used, if the box is overfull, or if a \vbox includes other boxes that have been shifted left.

Parameters: wfloat, default: 0A width. m{'exactly', 'additional'}, default: 'additional'Whether to produce a box whose width is 'exactly' w; or a box with the natural width of the contents, plus w ('additional').

Notes

The defaults produce a box with the natural width of the contents.

kern(self)[source]

Insert Kern nodes between Char nodes to set kerning.

The Char nodes themselves determine the amount of kerning they need (in get_kerning), and this function just creates the correct linked list.

class matplotlib.mathtext.Hrule(state, thickness=None)[source]

Bases: matplotlib.mathtext.Rule

Convenience class to create a horizontal rule.

class matplotlib.mathtext.Kern(width)[source]

Bases: matplotlib.mathtext.Node

A Kern node has a width field to specify a (normally negative) amount of spacing. This spacing correction appears in horizontal lists between letters like A and V when the font designer said that it looks better to move them closer together or further apart. A kern node can also appear in a vertical list, when its width denotes additional spacing in the vertical direction.

depth = 0
grow(self)[source]

Grows one level larger. There is no limit to how big something can get.

height = 0
shrink(self)[source]

Shrinks one level smaller. There are only three levels of sizes, after which things will no longer get smaller.

class matplotlib.mathtext.List(elements)[source]

Bases: matplotlib.mathtext.Box

A list of nodes (either horizontal or vertical).

grow(self)[source]

Grows one level larger. There is no limit to how big something can get.

shrink(self)[source]

Shrinks one level smaller. There are only three levels of sizes, after which things will no longer get smaller.

class matplotlib.mathtext.MathTextParser(output)[source]

Bases: object

Create a MathTextParser for the given backend output.

get_depth(self, texstr, dpi=120, fontsize=14)[source]
Parameters: texstrstrA valid mathtext string, e.g., r'IQ: $sigma_i=15$'. dpifloatThe dots-per-inch setting used to render the text. intOffset of the baseline from the bottom of the image, in pixels.
parse(self, s, dpi=72, prop=None)[source]

Parse the given math expression s at the given dpi. If prop is provided, it is a FontProperties object specifying the "default" font to use in the math expression, used for all non-math text.

The results are cached, so multiple calls to parse with the same expression should be fast.

Parameters: texstrstrA valid mathtext string, e.g., r'IQ: $sigma_i=15$'. dpifloatThe dots-per-inch setting used to render the text. fontsizeintThe font size in points array2D uint8 alphaMask array of rasterized tex. depthintOffset of the baseline from the bottom of the image, in pixels.
to_png(self, filename, texstr, color='black', dpi=120, fontsize=14)[source]

Render a tex expression to a PNG file.

Parameters: filenameA writable filename or fileobject. texstrstrA valid mathtext string, e.g., r'IQ: $sigma_i=15$'. colorcolorThe text color. dpifloatThe dots-per-inch setting used to render the text. fontsizeintThe font size in points. intOffset of the baseline from the bottom of the image, in pixels.
to_rgba(self, texstr, color='black', dpi=120, fontsize=14)[source]
Parameters: texstrstrA valid mathtext string, e.g., r'IQ: $sigma_i=15$'. colorcolorThe text color. dpifloatThe dots-per-inch setting used to render the text. fontsizeintThe font size in points. array(M, N, 4) arrayRGBA color values of rasterized tex, colorized with color. depthintOffset of the baseline from the bottom of the image, in pixels.
exception matplotlib.mathtext.MathTextWarning[source]

Bases: Warning

class matplotlib.mathtext.MathtextBackend[source]

Bases: object

The base class for the mathtext backend-specific code. MathtextBackend subclasses interface between mathtext and specific Matplotlib graphics backends.

Subclasses need to override the following:

And optionally, if you need to use a FreeType hinting style:

get_hinting_type(self)[source]

Get the FreeType hinting type to use with this particular backend.

get_results(self, box)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

render_glyph(self, ox, oy, info)[source]

Draw a glyph described by info to the reference point (ox, oy).

render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled black rectangle from (x1, y1) to (x2, y2).

set_canvas_size(self, w, h, d)[source]

Set the dimension of the drawing canvas.

class matplotlib.mathtext.MathtextBackendAgg[source]

Render glyphs and rectangles to an FTImage buffer, which is later transferred to the Agg image by the Agg backend.

get_hinting_type(self)[source]

Get the FreeType hinting type to use with this particular backend.

get_results(self, box, used_characters)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

render_glyph(self, ox, oy, info)[source]

Draw a glyph described by info to the reference point (ox, oy).

render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled black rectangle from (x1, y1) to (x2, y2).

set_canvas_size(self, w, h, d)[source]

Set the dimension of the drawing canvas.

class matplotlib.mathtext.MathtextBackendBitmap[source]
get_results(self, box, used_characters)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

class matplotlib.mathtext.MathtextBackendCairo[source]

Store information to write a mathtext rendering to the Cairo backend.

get_results(self, box, used_characters)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

render_glyph(self, ox, oy, info)[source]

Draw a glyph described by info to the reference point (ox, oy).

render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled black rectangle from (x1, y1) to (x2, y2).

class matplotlib.mathtext.MathtextBackendPath[source]

Store information to write a mathtext rendering to the text path machinery.

get_results(self, box, used_characters)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

render_glyph(self, ox, oy, info)[source]

Draw a glyph described by info to the reference point (ox, oy).

render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled black rectangle from (x1, y1) to (x2, y2).

class matplotlib.mathtext.MathtextBackendPdf[source]

Store information to write a mathtext rendering to the PDF backend.

get_results(self, box, used_characters)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

render_glyph(self, ox, oy, info)[source]

Draw a glyph described by info to the reference point (ox, oy).

render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled black rectangle from (x1, y1) to (x2, y2).

class matplotlib.mathtext.MathtextBackendPs[source]

Store information to write a mathtext rendering to the PostScript backend.

get_results(self, box, used_characters)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

render_glyph(self, ox, oy, info)[source]

Draw a glyph described by info to the reference point (ox, oy).

render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled black rectangle from (x1, y1) to (x2, y2).

class matplotlib.mathtext.MathtextBackendSvg[source]

Store information to write a mathtext rendering to the SVG backend.

get_results(self, box, used_characters)[source]

Return a backend-specific tuple to return to the backend after all processing is done.

render_glyph(self, ox, oy, info)[source]

Draw a glyph described by info to the reference point (ox, oy).

render_rect_filled(self, x1, y1, x2, y2)[source]

Draw a filled black rectangle from (x1, y1) to (x2, y2).

class matplotlib.mathtext.NegFil(**kwargs)[source]

Bases: matplotlib.mathtext.Glue

[Deprecated]

Notes

Deprecated since version 3.3:

class matplotlib.mathtext.NegFill(**kwargs)[source]

Bases: matplotlib.mathtext.Glue

[Deprecated]

Notes

Deprecated since version 3.3:

class matplotlib.mathtext.NegFilll(**kwargs)[source]

Bases: matplotlib.mathtext.Glue

[Deprecated]

Notes

Deprecated since version 3.3:

class matplotlib.mathtext.Node[source]

Bases: object

A node in the TeX box model.

get_kerning(self, next)[source]
grow(self)[source]

Grows one level larger. There is no limit to how big something can get.

render(self, x, y)[source]
shrink(self)[source]

Shrinks one level smaller. There are only three levels of sizes, after which things will no longer get smaller.

class matplotlib.mathtext.Parser[source]

Bases: object

A pyparsing-based parser for strings containing math expressions.

Raw text may also appear outside of pairs of \$.

The grammar is based directly on that in TeX, though it cuts a few corners.

class State(font_output, font, font_class, fontsize, dpi)[source]

Bases: object

Stores the state of the parser.

States are pushed and popped from a stack as necessary, and the "current" state is always at the top of the stack.

copy(self)[source]
property font
accent(self, s, loc, toks)[source]
accentprefixed(self, s, loc, toks)
auto_delim(self, s, loc, toks)[source]
binom(self, s, loc, toks)[source]
c_over_c(self, s, loc, toks)[source]
customspace(self, s, loc, toks)[source]
dfrac(self, s, loc, toks)[source]
end_group(self, s, loc, toks)[source]
font(self, s, loc, toks)[source]
frac(self, s, loc, toks)[source]
function(self, s, loc, toks)[source]
genfrac(self, s, loc, toks)[source]
get_state(self)[source]

Get the current State of the parser.

group(self, s, loc, toks)[source]
is_between_brackets(self, s, loc)[source]
is_dropsub(self, nucleus)[source]
is_overunder(self, nucleus)[source]
is_slanted(self, nucleus)[source]
main(self, s, loc, toks)[source]
math(self, s, loc, toks)[source]
math_string(self, s, loc, toks)[source]
non_math(self, s, loc, toks)[source]
operatorname(self, s, loc, toks)[source]
overline(self, s, loc, toks)[source]
parse(self, s, fonts_object, fontsize, dpi)[source]

Parse expression s using the given fonts_object for output, at the given fontsize and dpi.

Returns the parse tree of Node instances.

pop_state(self)[source]

Pop a State off of the stack.

push_state(self)[source]

Push a new State onto the stack, copying the current state.

required_group(self, s, loc, toks)
simple_group(self, s, loc, toks)
space(self, s, loc, toks)[source]
sqrt(self, s, loc, toks)[source]
start_group(self, s, loc, toks)[source]
subsuper(self, s, loc, toks)[source]
symbol(self, s, loc, toks)[source]
unknown_symbol(self, s, loc, toks)[source]
class matplotlib.mathtext.Rule(width, height, depth, state)[source]

Bases: matplotlib.mathtext.Box

A solid black rectangle.

It has width, depth, and height fields just as in an Hlist. However, if any of these dimensions is inf, the actual value will be determined by running the rule up to the boundary of the innermost enclosing box. This is called a "running dimension". The width is never running in an Hlist; the height and depth are never running in a Vlist.

render(self, x, y, w, h)[source]
class matplotlib.mathtext.STIXFontConstants[source]
delta = 0.05
delta_integral = 0.3
delta_slanted = 0.3
script_space = 0.1
sub2 = 0.6
sup1 = 0.8
class matplotlib.mathtext.STIXSansFontConstants[source]
delta_integral = 0.3
delta_slanted = 0.6
script_space = 0.05
sup1 = 0.8
class matplotlib.mathtext.Ship[source]

Bases: object

Ship boxes to output once they have been set up, this sends them to output.

Since boxes can be inside of boxes inside of boxes, the main work of Ship is done by two mutually recursive routines, hlist_out and vlist_out, which traverse the Hlist nodes and Vlist nodes inside of horizontal and vertical boxes. The global variables used in TeX to store state as it processes have become member variables here.

static clamp(value)[source]
hlist_out(self, box)[source]
vlist_out(self, box)[source]
class matplotlib.mathtext.SsGlue(**kwargs)[source]

Bases: matplotlib.mathtext.Glue

[Deprecated]

Notes

Deprecated since version 3.3:

class matplotlib.mathtext.StandardPsFonts(default_font_prop)[source]

Use the standard postscript fonts for rendering to backend_ps

Unlike the other font classes, BakomaFont and UnicodeFont, this one requires the Ps backend.

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
basepath = '/usr/local/lib64/python3.8/site-packages/matplotlib/mpl-data/fonts/afm'
fontmap = {'cal': 'pzcmi8a', 'rm': 'pncr8a', 'tt': 'pcrr8a', 'it': 'pncri8a', 'sf': 'phvr8a', 'bf': 'pncb8a', None: 'psyr'}
get_kern(self, font1, fontclass1, sym1, fontsize1, font2, fontclass2, sym2, fontsize2, dpi)[source]

Get the kerning distance for font between sym1 and sym2.

fontX: one of the TeX font names:

tt, it, rm, cal, sf, bf or default/regular (non-math)

fontclassX: TODO

symX: a symbol in raw TeX form. e.g., '1', 'x' or 'sigma'

fontsizeX: the fontsize in points

dpi: the current dots-per-inch

get_underline_thickness(self, font, fontsize, dpi)[source]

Get the line thickness that matches the given font. Used as a base unit for drawing lines such as in a fraction or radical.

get_xheight(self, font, fontsize, dpi)[source]

Get the xheight for the given font and fontsize.

class matplotlib.mathtext.StixFonts(*args, **kwargs)[source]

A font handling class for the STIX fonts.

In addition to what UnicodeFonts provides, this class:

• supports "virtual fonts" which are complete alpha numeric character sets with different font styles at special Unicode code points, such as "Blackboard".
• handles sized alternative characters for the STIXSizeX fonts.
Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
cm_fallback = False
get_sized_alternatives_for_symbol(self, fontname, sym)[source]

Override if your font provides multiple sizes of the same symbol. Should return a list of symbols matching sym in various sizes. The expression renderer will select the most appropriate size for a given situation from this list.

use_cmex = False
class matplotlib.mathtext.StixSansFonts(*args, **kwargs)[source]

A font handling class for the STIX fonts (that uses sans-serif characters by default).

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
class matplotlib.mathtext.SubSuperCluster[source]

A hack to get around that fact that this code does a two-pass parse like TeX. This lets us store enough information in the hlist itself, namely the nucleus, sub- and super-script, such that if another script follows that needs to be attached, it can be reconfigured on the fly.

class matplotlib.mathtext.TruetypeFonts(default_font_prop, mathtext_backend)[source]

A generic base class for all font setups that use Truetype fonts (through FT2Font).

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
destroy(self)[source]

Fix any cyclical references before the object is about to be destroyed.

get_kern(self, font1, fontclass1, sym1, fontsize1, font2, fontclass2, sym2, fontsize2, dpi)[source]

Get the kerning distance for font between sym1 and sym2.

fontX: one of the TeX font names:

tt, it, rm, cal, sf, bf or default/regular (non-math)

fontclassX: TODO

symX: a symbol in raw TeX form. e.g., '1', 'x' or 'sigma'

fontsizeX: the fontsize in points

dpi: the current dots-per-inch

get_underline_thickness(self, font, fontsize, dpi)[source]

Get the line thickness that matches the given font. Used as a base unit for drawing lines such as in a fraction or radical.

get_xheight(self, fontname, fontsize, dpi)[source]

Get the xheight for the given font and fontsize.

class matplotlib.mathtext.UnicodeFonts(*args, **kwargs)[source]

An abstract base class for handling Unicode fonts.

While some reasonably complete Unicode fonts (such as DejaVu) may work in some situations, the only Unicode font I'm aware of with a complete set of math symbols is STIX.

This class will "fallback" on the Bakoma fonts when a required symbol can not be found in the font.

Parameters: default_font_prop: ~.font_manager.FontPropertiesThe default non-math font, or the base font for Unicode (generic) font rendering. mathtext_backend: MathtextBackend subclassBackend to which rendering is actually delegated.
get_sized_alternatives_for_symbol(self, fontname, sym)[source]

Override if your font provides multiple sizes of the same symbol. Should return a list of symbols matching sym in various sizes. The expression renderer will select the most appropriate size for a given situation from this list.

use_cmex = True
class matplotlib.mathtext.VCentered(elements)[source]

A convenience class to create a Vlist whose contents are centered within its enclosing box.

class matplotlib.mathtext.Vbox(height, depth)[source]

Bases: matplotlib.mathtext.Box

A box with only height (zero width).

Bases: matplotlib.mathtext.List

A vertical list of boxes.

Compute the dimensions of the resulting boxes, and to adjust the glue if one of those dimensions is pre-specified.

Parameters: hfloat, default: 0A height. m{'exactly', 'additional'}, default: 'additional'Whether to produce a box whose height is 'exactly' w; or a box with the natural height of the contents, plus w ('additional'). lfloat, default: np.infThe maximum height.

Notes

The defaults produce a box with the natural height of the contents.

class matplotlib.mathtext.Vrule(state)[source]

Bases: matplotlib.mathtext.Rule

Convenience class to create a vertical rule.

matplotlib.mathtext.get_unicode_index(symbol, math=True)[source]

Return the integer index (from the Unicode table) of symbol.

Parameters: symbolstrA single unicode character, a TeX command (e.g. r'pi') or a Type1 symbol name (e.g. 'phi'). mathbool, default: TrueIf False, always treat as a single unicode character.
matplotlib.mathtext.math_to_image(s, filename_or_obj, prop=None, dpi=None, format=None)[source]

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

Parameters: sstrA math expression. The math portion must be enclosed in dollar signs. filename_or_objstr or path-like or file-likeWhere to write the image data. propFontProperties, optionalThe size and style of the text. dpifloat, optionalThe output dpi. If not set, the dpi is determined as for Figure.savefig. formatstr, optionalThe output format, e.g., 'svg', 'pdf', 'ps' or 'png'. If not set, the format is determined as for Figure.savefig.