|
1 | 1 | r""" |
2 | | -Support for embedded TeX expressions in Matplotlib via dvipng and dvips for the |
3 | | -raster and PostScript backends. The tex and dvipng/dvips information is cached |
4 | | -in ~/.matplotlib/tex.cache for reuse between sessions. |
| 2 | +Support for embedded TeX expressions in Matplotlib. |
5 | 3 |
|
6 | 4 | Requirements: |
7 | 5 |
|
8 | | -* LaTeX |
9 | | -* \*Agg backends: dvipng>=1.6 |
10 | | -* PS backend: psfrag, dvips, and Ghostscript>=9.0 |
11 | | -
|
12 | | -For raster output, you can get RGBA numpy arrays from TeX expressions |
13 | | -as follows:: |
14 | | -
|
15 | | - texmanager = TexManager() |
16 | | - s = "\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!" |
17 | | - Z = texmanager.get_rgba(s, fontsize=12, dpi=80, rgb=(1, 0, 0)) |
| 6 | +* LaTeX. |
| 7 | +* \*Agg backends: dvipng>=1.6. |
| 8 | +* PS backend: PSfrag, dvips, and Ghostscript>=9.0. |
| 9 | +* PDF and SVG backends: if LuaTeX is present, it will be used to speed up some |
| 10 | + post-processing steps, but note that it is not used to parse the TeX string |
| 11 | + itself (only LaTeX is supported). |
18 | 12 |
|
19 | 13 | To enable TeX rendering of all text in your Matplotlib figure, set |
20 | 14 | :rc:`text.usetex` to True. |
| 15 | +
|
| 16 | +TeX and dvipng/dvips processing results are cached |
| 17 | +in ~/.matplotlib/tex.cache for reuse between sessions. |
| 18 | +
|
| 19 | +`TexManager.get_rgba` can also be used to directly obtain raster output as RGBA |
| 20 | +numpy arrays. |
21 | 21 | """ |
22 | 22 |
|
23 | 23 | import functools |
@@ -274,7 +274,15 @@ def get_grey(self, tex, fontsize=None, dpi=None): |
274 | 274 | return alpha |
275 | 275 |
|
276 | 276 | def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0, 0, 0)): |
277 | | - """Return latex's rendering of the tex string as an rgba array.""" |
| 277 | + r""" |
| 278 | + Return latex's rendering of the tex string as an rgba array. |
| 279 | +
|
| 280 | + Examples |
| 281 | + -------- |
| 282 | + >>> texmanager = TexManager() |
| 283 | + >>> s = r"\TeX\ is $\displaystyle\sum_n\frac{-e^{i\pi}}{2^n}$!" |
| 284 | + >>> Z = texmanager.get_rgba(s, fontsize=12, dpi=80, rgb=(1, 0, 0)) |
| 285 | + """ |
278 | 286 | alpha = self.get_grey(tex, fontsize, dpi) |
279 | 287 | rgba = np.empty((*alpha.shape, 4)) |
280 | 288 | rgba[..., :3] = mpl.colors.to_rgb(rgb) |
|
0 commit comments