Matplotlib is hiring a Research Software Engineering Fellow! See discourse for details. Apply by January 3, 2020
matplotlib.textpath¶matplotlib.textpath.TextPath(xy, s, size=None, prop=None, _interpolation_steps=1, usetex=False, *kl, **kwargs)[源代码]¶从文本创建路径。
从文本创建路径。请注意,它只是一条路径,而不是艺术家。你需要使用 PathPatch (或其他艺术家)将此路径绘制到画布上。
| 参数: |
|
|---|
实例
下面从字符串“abc”创建一个带有helvetica字体的路径;从 Latex 分数1/2创建另一个路径:
from matplotlib.textpath import TextPath
from matplotlib.font_manager import FontProperties
fp = FontProperties(family="Helvetica", style="italic")
path1 = TextPath((12,12), "ABC", size=12, prop=fp)
path2 = TextPath((0,0), r"$\frac{1}{2}$", size=12, usetex=True)
也看到 演示文本路径 .
codes¶返回代码
vertices¶如果需要,请在更新缓存路径后返回该路径。
matplotlib.textpath.TextToPath[源代码]¶基类:object
使用TTF字体将给定文本转换为路径的类。
DPI = 72¶FONT_SCALE = 100.0¶get_glyphs_mathtext(prop, s, glyph_map=None, return_new_glyphs_only=False)[源代码]¶转换字符串 s 通过用MathText解析顶点和代码。
get_glyphs_tex(prop, s, glyph_map=None, return_new_glyphs_only=False)[源代码]¶转换字符串 s 到使用matplotlib的usetex模式的顶点和代码。
get_glyphs_with_font(font, s, glyph_map=None, return_new_glyphs_only=False)[源代码]¶转换字符串 s 使用提供的TTF字体的顶点和代码。
get_text_path(prop, s, ismath=False, usetex=False)[源代码]¶转换文本 s 到路径(matplotlib.path.path的顶点和代码的元组)。
| 参数: |
|
|---|---|
| 返回: |
|
实例
从文本创建顶点和代码列表,并创建 Path 从:
from matplotlib.path import Path
from matplotlib.textpath import TextToPath
from matplotlib.font_manager import FontProperties
fp = FontProperties(family="Humor Sans", style="italic")
verts, codes = TextToPath().get_text_path(fp, "ABC")
path = Path(verts, codes, closed=False)
也看到 TextPath 以更直接的方式从文本创建路径。
tex_font_map¶3.0 版后已移除: tex_font_map函数在matplotlib 3.0中已弃用,将在3.2中删除。