matplotlib.texmanager
在 Matplotlib 中支持嵌入的 TeX 表达式。
要求:
要在 Matplotlib 图形中启用所有文本的 TeX 渲染,请将 rcParams["text.usetex"]
(default: False
) 设置为 True。
TeX 和 dvipng/dvips 处理结果被缓存在 ~/.matplotlib/tex.cache 中,以便在会话之间重复使用。
TexManager.get_rgba
也可以用于直接获取以 RGBA NumPy 数组形式表示的栅格输出。
-
class matplotlib.texmanager.TexManager[源代码][源代码]
基类:object
使用 TeX 将字符串转换为 dvi 文件,并将结果缓存到目录中。
缓存目录被称为 tex.cache
,位于 get_cachedir
返回的目录中。
对此构造函数的重复调用总是返回同一个实例。
-
classmethod get_basefile(tex, fontsize, dpi=None)[源代码][源代码]
基于字符串、字体大小和dpi的哈希值返回一个文件名。
-
classmethod get_custom_preamble()[源代码][源代码]
返回一个包含用户对tex前言添加的字符串。
-
classmethod get_font_preamble()[源代码][源代码]
返回一个包含用于tex前言的字体配置的字符串。
-
classmethod get_grey(tex, fontsize=None, dpi=None)[源代码][源代码]
返回 alpha 通道。
-
classmethod get_rgba(tex, fontsize=None, dpi=None, rgb=(0, 0, 0))[源代码][源代码]
将tex字符串的latex渲染结果作为RGBA数组返回。
示例
>>> 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))
-
classmethod get_text_width_height_descent(tex, fontsize, renderer=None)[源代码][源代码]
返回文本的宽度、高度和下降值。
-
classmethod make_dvi(tex, fontsize)[源代码][源代码]
生成一个包含 tex 字符串的 latex 布局的 dvi 文件。
返回文件名。
-
classmethod make_png(tex, fontsize, dpi)[源代码][源代码]
生成一个包含tex字符串的latex渲染的png文件。
返回文件名。
-
classmethod make_tex(tex, fontsize)[源代码][源代码]
生成一个 tex 文件以在特定字体大小下渲染 tex 字符串。
返回文件名。
-
property texcache[源代码]
!! 由 numpydoc 处理 !!