MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / math_to_image

Function math_to_image

lib/matplotlib/mathtext.py:108–140  ·  view source on GitHub ↗

Given a math expression, renders it in a closely-clipped bounding box to an image file. Parameters ---------- s : str A math expression. The math portion must be enclosed in dollar signs. filename_or_obj : str or path-like or file-like Where to write the im

(s, filename_or_obj, prop=None, dpi=None, format=None,
                  *, color=None)

Source from the content-addressed store, hash-verified

106
107
108def math_to_image(s, filename_or_obj, prop=None, dpi=None, format=None,
109 *, color=None):
110 """
111 Given a math expression, renders it in a closely-clipped bounding
112 box to an image file.
113
114 Parameters
115 ----------
116 s : str
117 A math expression. The math portion must be enclosed in dollar signs.
118 filename_or_obj : str or path-like or file-like
119 Where to write the image data.
120 prop : `.FontProperties`, optional
121 The size and style of the text.
122 dpi : float, optional
123 The output dpi. If not set, the dpi is determined as for
124 `.Figure.savefig`.
125 format : str, optional
126 The output format, e.g., 'svg', 'pdf', 'ps' or 'png'. If not set, the
127 format is determined as for `.Figure.savefig`.
128 color : str, optional
129 Foreground color, defaults to :rc:`text.color`.
130 """
131 from matplotlib import figure
132
133 parser = MathTextParser('path')
134 width, height, depth, _, _ = parser.parse(s, dpi=72, prop=prop)
135
136 fig = figure.Figure(figsize=(width / 72.0, height / 72.0))
137 fig.text(0, depth/height, s, fontproperties=prop, color=color)
138 fig.savefig(filename_or_obj, dpi=dpi, format=format)
139
140 return depth

Callers

nothing calls this directly

Calls 4

parseMethod · 0.95
savefigMethod · 0.95
MathTextParserClass · 0.85
textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…