matplotlib.mathtext
#
用于解析 TeX 数学语法子集并将其渲染到 Matplotlib 后端的模块。
有关其用法的教程,请参阅编写数学表达式。本文档主要关注实现细节。
该模块使用 pyparsing 来解析 TeX 表达式。
支持 TeX Computer Modern 字体和 STIX 字体中的 Bakoma 发行版。对使用任意字体提供实验性支持,但如果没有对这些字体进行适当的调整和度量,结果可能会有所不同。
- class matplotlib.mathtext.MathTextParser(output)[source]#
基类:
object
为给定的后端 output 创建一个 MathTextParser。
- 参数:
- output{"path", "agg"}
是返回
VectorParse
("path")还是返回RasterParse
("agg" 或其同义词 "macosx")。
- parse(s, dpi=72, prop=None, *, antialiased=None)[source]#
以给定的 dpi 解析给定的数学表达式 s。如果提供了 prop,它是一个
FontProperties
对象,指定在数学表达式中使用的“默认”字体,用于所有非数学文本。结果会被缓存,因此对
parse
使用相同表达式的多次调用会很快。根据 output 类型,此函数返回
VectorParse
或RasterParse
。
- class matplotlib.mathtext.RasterParse(ox, oy, width, height, depth, image)[source]#
基类:
NamedTuple
MathTextParser("agg").parse(...)
返回的 namedtuple 类型。- 属性:
- ox, oyfloat
偏移量始终为零。
- width, height, depthfloat
全局度量。
- imageFT2Image
栅格图像。
创建 RasterParse(ox, oy, width, height, depth, image) 的新实例
- depth#
字段编号 4 的别名
- height#
字段编号 3 的别名
- image#
字段编号 5 的别名
- ox#
字段编号 0 的别名
- oy#
字段编号 1 的别名
- width#
字段编号 2 的别名
- class matplotlib.mathtext.VectorParse(width, height, depth, glyphs, rects)[source]#
基类:
NamedTuple
MathTextParser("path").parse(...)
返回的 namedtuple 类型。- 属性:
- width, height, depthfloat
全局度量。
- glyphslist
包含其位置的字形。
- rectlist
矩形列表。
创建 VectorParse(width, height, depth, glyphs, rects) 的新实例
- depth#
字段编号 2 的别名
- glyphs#
字段编号 3 的别名
- height#
字段编号 1 的别名
- rects#
字段编号 4 的别名
- width#
字段编号 0 的别名
- matplotlib.mathtext.get_unicode_index(symbol)[source]#
返回 symbol 的整数索引(来自 Unicode 表)。
- 参数:
- symbolstr
单个(Unicode)字符、TeX 命令(例如 r'pi')或 Type1 符号名称(例如 'phi')。
- matplotlib.mathtext.math_to_image(s, filename_or_obj, prop=None, dpi=None, format=None, *, color=None)[source]#
给定一个数学表达式,将其渲染到一个紧密裁剪的边界框中的图像文件。
- 参数:
- sstr
数学表达式。数学部分必须用美元符号括起来。
- filename_or_objstr 或 path-like 或 file-like
写入图像数据的位置。
- prop
FontProperties
, 可选 文本的大小和样式。
- dpifloat, 可选
输出 dpi。如果未设置,dpi 将根据
Figure.savefig
确定。- formatstr, 可选
输出格式,例如 'svg'、'pdf'、'ps' 或 'png'。如果未设置,格式将根据
Figure.savefig
确定。- colorstr, 可选
前景颜色,默认为
rcParams["text.color"]
(默认值:'black'
)。