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)
| 106 | |
| 107 | |
| 108 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…