matplotlib.mathtext
¶

用于解析TeX数学语法子集并将其呈现给Matplotlib后端的模块。
有关其用法的教程,请参见 写数学表达式 . 本文件主要涉及实施细节。
模块使用 pyparsing 解析tex表达式。
支持Tex计算机现代字体和Stix字体的Bakoma发行版。对使用任意字体有实验性的支持,但是如果没有适当的调整和度量,结果可能会有所不同。
-
class
matplotlib.mathtext.
Accent
(c, state, math=True)[源代码]¶ -
对于重音符号,字体度量需要进行不同的处理,因为它们已经从TrueType字体的基线正确偏移。
-
class
matplotlib.mathtext.
AutoHeightChar
(c, height, depth, state, always=False, factor=None)[源代码]¶ -
尽可能接近给定高度和深度的字符。
当使用具有某些字符的多个高度版本(如BaKoMa字体)的字体时,将选择正确的字形,否则将始终返回字形的缩放版本。
-
class
matplotlib.mathtext.
AutoWidthChar
(c, width, state, always=False, char_class=<class 'matplotlib.mathtext.Char'>)[源代码]¶ -
尽可能接近给定宽度的字符。
当使用具有某些字符的多个宽度版本(如BaKoMa字体)的字体时,将选择正确的字形,否则将始终返回字形的缩放版本。
-
class
matplotlib.mathtext.
BakomaFonts
(*args, **kwargs)[源代码]¶ 基类:
matplotlib.mathtext.TruetypeFonts
使用Bakoma TrueType字体进行渲染。
符号散布在许多字体文件上,每个字体文件都有自己专有的8位编码。
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
alias
= '\\]'¶
-
get_sized_alternatives_for_symbol
(fontname, sym)[源代码]¶ 如果字体提供同一符号的多个大小,则重写。应返回匹配的符号列表 sym 各种尺寸。表达式渲染器将从此列表中为给定情况选择最合适的大小。
-
target
= ']'¶
-
class
matplotlib.mathtext.
Char
(c, state, math=True)[源代码]¶ -
一个字符。
与TeX不同,字体信息和度量存储在每个
Char
以便于在需要时查找字体度量。请注意,TeX框具有宽度、高度和深度,这与Type1和TrueType不同,后者使用全边界框和x方向的前进。度量必须转换为TeX模型,并且进阶(如果与宽度不同)必须转换为Kern
节点时Char
添加到其父级Hlist
.
-
class
matplotlib.mathtext.
ComputerModernFontConstants
[源代码]¶ 基类:
matplotlib.mathtext.FontConstantsBase
-
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)[源代码]¶ 基类:
matplotlib.mathtext.UnicodeFonts
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
use_cmex
= False¶
-
class
matplotlib.mathtext.
DejaVuSansFonts
(*args, **kwargs)[源代码]¶ 基类:
matplotlib.mathtext.DejaVuFonts
dejavu sans字体的字体处理类
如果找不到glyph,它将回退到stix sans
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
class
matplotlib.mathtext.
DejaVuSerifFonts
(*args, **kwargs)[源代码]¶ 基类:
matplotlib.mathtext.DejaVuFonts
dejavu serif字体的字体处理类
如果找不到glyph,它将回退到stix serif
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
class
matplotlib.mathtext.
FontConstantsBase
[源代码]¶ 基类:
object
一组常量,用于控制某些事物(如子脚本和上标)的布局。这些都是无法从字体本身的字体度量中可靠地检索到的度量。
-
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)[源代码]¶ 基类:
object
用于MathText的字体系统的抽象基类。
类必须能够获取符号键和字体文件名并返回字符度量。它还委托给后端类来进行实际的绘图。
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
get_kern
(font1, fontclass1, sym1, fontsize1, font2, fontclass2, sym2, fontsize2, dpi)[源代码]¶ 获取字体间距 sym1 和 sym2 .
芬太克斯 :Tex字体名称之一:
tt, it, rm, cal, sf, bf or default/regular (non-math)
FordCaseX 待办事项
symX :原始tex形式的符号。例如,“1”、“X”或“Sigma”
芬茨赛克斯 :字体大小(以磅为单位)
dpi :当前每英寸点数
-
get_metrics
(font, font_class, sym, fontsize, dpi, math=True)[源代码]¶ font :Tex字体名称之一:
tt, it, rm, cal, sf, bf or default/regular (non-math)
font_class 待办事项
sym :原始tex形式的符号。例如,“1”、“X”或“Sigma”
字体大小 :字体大小(以磅为单位)
dpi :当前每英寸点数
math :sym是否为数学字符
返回具有以下属性的对象:
- 提前 :标志符号的前进距离(以点为单位)。
- 高度 :标志符号的高度(以点为单位)。
- 宽度 :字形的宽度(以点为单位)。
- xmin , xmax , ymin , ymax -字形的墨迹矩形
- 冰山 -从基线到字形顶部的距离。这符合Tex对“高度”的定义。
-
get_sized_alternatives_for_symbol
(fontname, sym)[源代码]¶ 如果字体提供同一符号的多个大小,则重写。应返回匹配的符号列表 sym 各种尺寸。表达式渲染器将从此列表中为给定情况选择最合适的大小。
-
class
matplotlib.mathtext.
Glue
(glue_type, copy=<deprecated parameter>)[源代码]¶ -
此对象中的大部分信息存储在底层
_GlueSpec
类,在多个粘合对象之间共享。(这是一个内存优化,可能不再重要了,但更容易坚持tex的做法。)-
property
glue_subtype
¶
-
property
-
class
matplotlib.mathtext.
GlueSpec
(width=0.0, stretch=0.0, stretch_order=0, shrink=0.0, shrink_order=0)[源代码]¶ 基类:
object
[Deprecated] 见
Glue
.笔记
3.3 版后已移除.
-
class
matplotlib.mathtext.
Hlist
(elements, w=0.0, m='additional', do_kern=True)[源代码]¶ -
一个水平的框列表。
-
class
matplotlib.mathtext.
Kern
(width)[源代码]¶ -
A
Kern
节点有一个宽度字段来指定(通常为负)间距。当字体设计人员说将A和V这样的字母靠得更近或更远时,这种间距更正会出现在水平列表中。紧排节点也可以出现在垂直列表中,当 宽度 表示垂直方向上的附加间距。-
depth
= 0¶
-
height
= 0¶
-
-
class
matplotlib.mathtext.
MathTextParser
(output)[源代码]¶ 基类:
object
为给定后端创建MathTextParser 输出 .
-
get_depth
(texstr, dpi=120, fontsize=14)[源代码]¶ 参数: - texstrSTR
有效的mathtext字符串,例如r'IQ:$sigma_i=15$'。
- dpi浮动
用于呈现文本的每英寸点数设置。
返回: - 利息
基线距图像底部的偏移量,以像素为单位。
-
parse
(s, dpi=72, prop=None)[源代码]¶ 解析给定的数学表达式 s 在给定的 dpi . 如果 prop 提供,它是
FontProperties
对象,指定要在数学表达式中使用的“默认”字体,用于所有非数学文本。结果被缓存,因此多次调用
parse
用同样的表达式应该是快速的。
-
to_mask
(texstr, dpi=120, fontsize=14)[源代码]¶ 参数: - texstrSTR
有效的mathtext字符串,例如r'IQ:$sigma_i=15$'。
- dpi浮动
用于呈现文本的每英寸点数设置。
- fontsize利息
以磅为单位的字体大小
返回: - array2D uint8阿尔法
栅格化纹理的掩模数组。
- depth利息
基线距图像底部的偏移量,以像素为单位。
-
-
class
matplotlib.mathtext.
MathtextBackend
[源代码]¶ 基类:
object
mathtext后端特定代码的基类。
MathtextBackend
mathtext和特定Matplotlib图形后端之间的子类接口。子类需要重写以下内容:
如果需要使用freetype提示样式,还可以选择:
-
class
matplotlib.mathtext.
MathtextBackendAgg
[源代码]¶ 基类:
matplotlib.mathtext.MathtextBackend
将glyph和矩形渲染到ftimage缓冲区,该缓冲区随后由agg后端传输到agg映像。
-
class
matplotlib.mathtext.
MathtextBackendCairo
[源代码]¶ 基类:
matplotlib.mathtext.MathtextBackend
存储信息以将MathText呈现写入cairo后端。
-
class
matplotlib.mathtext.
MathtextBackendPath
[源代码]¶ 基类:
matplotlib.mathtext.MathtextBackend
存储信息以将MathText呈现写入文本路径机器。
-
class
matplotlib.mathtext.
MathtextBackendPdf
[源代码]¶ 基类:
matplotlib.mathtext.MathtextBackend
存储信息以将MathText呈现写入PDF后端。
-
class
matplotlib.mathtext.
MathtextBackendPs
[源代码]¶ 基类:
matplotlib.mathtext.MathtextBackend
存储将数学文本呈现写入PostScript后端的信息。
-
class
matplotlib.mathtext.
MathtextBackendSvg
[源代码]¶ 基类:
matplotlib.mathtext.MathtextBackend
存储信息以将MathText呈现写入SVG后端。
-
class
matplotlib.mathtext.
Parser
[源代码]¶ 基类:
object
一个基于pyparsing的解析器,用于包含数学表达式的字符串。
原始文本也可能出现在成对文本之外
$
.语法直接基于tex中的语法,尽管它有几个角。
-
class
State
(font_output, font, font_class, fontsize, dpi)[源代码]¶ 基类:
object
存储分析器的状态。
根据需要从堆栈中推送和弹出状态,“当前”状态始终位于堆栈顶部。
-
property
font
¶
-
property
-
accentprefixed
(s, loc, toks)¶
-
parse
(s, fonts_object, fontsize, dpi)[源代码]¶ 分析表达式 s 使用给定的 fonts_object 对于输出,在给定的 字体大小 和 dpi .
返回的分析树
Node
实例。
-
required_group
(s, loc, toks)¶
-
simple_group
(s, loc, toks)¶
-
class
-
class
matplotlib.mathtext.
Rule
(width, height, depth, state)[源代码]¶ -
实心黑色矩形。
它有 宽度 , 深度 和 高度 字段与
Hlist
. 但是,如果这些维度中的任何一个是inf,则实际值将通过运行规则直到最里面的封闭框的边界来确定。这被称为“运行维度”。宽度永远不会在Hlist
;高度和深度从未在Vlist
.
-
class
matplotlib.mathtext.
STIXFontConstants
[源代码]¶ 基类:
matplotlib.mathtext.FontConstantsBase
-
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
[源代码]¶ 基类:
matplotlib.mathtext.FontConstantsBase
-
delta_integral
= 0.3¶
-
delta_slanted
= 0.6¶
-
script_space
= 0.05¶
-
sup1
= 0.8¶
-
-
class
matplotlib.mathtext.
Ship
[源代码]¶ 基类:
object
将框发送到输出一旦它们被设置好,这会将它们发送到输出。
既然盒子可以是盒子里面的盒子里面的盒子,主要的工作就是
Ship
由两个相互递归的例程完成,hlist_out
和vlist_out
,横穿Hlist
节点和Vlist
水平和垂直框内的节点。TEX中用于存储状态的全局变量在这里已经成为成员变量。
-
class
matplotlib.mathtext.
StandardPsFonts
(default_font_prop)[源代码]¶ -
使用标准PostScript字体渲染到后端
与其他字体类BakomaFont和UnicodeFont不同,这一类需要PS后端。
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
basepath
= '/tmp/vpy_mat/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/afm'¶
-
fontmap
= {'cal': 'pzcmi8a', 'rm': 'pncr8a', 'tt': 'pcrr8a', 'it': 'pncri8a', 'sf': 'phvr8a', 'bf': 'pncb8a', None: 'psyr'}¶
-
class
matplotlib.mathtext.
StixFonts
(*args, **kwargs)[源代码]¶ 基类:
matplotlib.mathtext.UnicodeFonts
Stix字体的字体处理类。
除了unicodefonts提供的内容外,此类还包括:
- 支持“虚拟字体”,它是在特殊的Unicode代码点(如“黑板”)具有不同字体样式的完整字母数字字符集。
- 处理StixSizex字体的大小可选字符。
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
cm_fallback
= False¶
-
get_sized_alternatives_for_symbol
(fontname, sym)[源代码]¶ 如果字体提供同一符号的多个大小,则重写。应返回匹配的符号列表 sym 各种尺寸。表达式渲染器将从此列表中为给定情况选择最合适的大小。
-
use_cmex
= False¶
-
class
matplotlib.mathtext.
StixSansFonts
(*args, **kwargs)[源代码]¶ 基类:
matplotlib.mathtext.StixFonts
Stix字体的字体处理类(默认使用无衬线字符)。
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
class
matplotlib.mathtext.
SubSuperCluster
[源代码]¶ -
这是一个绕过这个事实的黑客,这个代码像TeX一样进行两次解析。这让我们在hlist本身中存储足够的信息,即nucleus、sub和super脚本,这样如果后面有另一个需要附加的脚本,就可以动态地重新配置它。
-
class
matplotlib.mathtext.
TruetypeFonts
(default_font_prop, mathtext_backend)[源代码]¶ -
所有使用TrueType字体(通过ft2font)的字体设置的通用基类。
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
class
matplotlib.mathtext.
UnicodeFonts
(*args, **kwargs)[源代码]¶ 基类:
matplotlib.mathtext.TruetypeFonts
用于处理Unicode字体的抽象基类。
虽然某些相当完整的Unicode字体(如Dejavu)在某些情况下可能会工作,但对于一组完整的数学符号,我所知道的唯一Unicode字体是Stix。
当在字体中找不到所需符号时,此类将在bakoma字体上“回退”。
参数: - default_font_prop: `~.font_manager.FontProperties`
默认的非数学字体,或Unicode(通用)字体呈现的基础字体。
- mathtext_backend: `MathtextBackend` subclass
渲染实际委托给的后端。
-
get_sized_alternatives_for_symbol
(fontname, sym)[源代码]¶ 如果字体提供同一符号的多个大小,则重写。应返回匹配的符号列表 sym 各种尺寸。表达式渲染器将从此列表中为给定情况选择最合适的大小。
-
use_cmex
= True¶
-
matplotlib.mathtext.
get_unicode_index
(symbol, math=True)[源代码]¶ 返回的整数索引(来自Unicode表) 符号 .
参数: - symbolSTR
单字符(例如'A.g.A.g。
- mathbool,默认值:True
如果为False,则始终将其视为单个unicode字符。
-
matplotlib.mathtext.
math_to_image
(s, filename_or_obj, prop=None, dpi=None, format=None)[源代码]¶ 给定一个数学表达式,将它在一个紧密剪裁的边界框中渲染为图像文件。
参数: - sSTR
数学表达式。数学部分必须用美元符号括起来。
- filename_or_objstr或path like或file like
在何处写入图像数据。
- prop :
FontProperties
可选字体属性,可选 文本的大小和样式。
- dpi可选浮动
输出dpi。如果未设置,则dpi确定为
Figure.savefig
.- format可选的STR
输出格式,例如“svg”、“pdf”、“ps”或“png”。如果未设置,则格式确定为
Figure.savefig
.