Writing mathematical expressions — Matplotlib 3.6.2 documentation
You can use a subset of TeX markup in any Matplotlib text string by placing it inside a pair of dollar signs ($). Note that you do not need to have TeX installed, since Matplotlib ships its own TeX expression parser, layout engine, and fonts. The layout engine is a fairly direct adaptation of the layout algorithms in Donald Knuth's TeX, so the quality is quite good (Matplotlib also provides a usetex option for those who do want to call out to TeX to generate their text; see Text rendering with LaTeX). Any text element can use math text. You should use raw strings (precede the quotes with an 'r'), and surround the math text with dollar signs ($), as in TeX. Regular text and mathtext can be interleaved within the same string. Mathtext can use DejaVu Sans (default), DejaVu Serif, the Computer Modern fonts (from (La)TeX), STIX fonts (which are designed to blend well with Times), or a Unicode font that you provide. The mathtext font can be selected via rcParams["mathtext.fontset"] (default:
Note Go to the end to download the full example code. Matplotlib implements a lightweight TeX expression parser and layout engine and Mathtext is the subset of Tex markup that this engine supports. Note that Matplotlib can also render all text directly using TeX if rcParams["text.usetex"] (default: False) is True; see Text rendering with LaTeX for more details. Mathtext support is available if rcParams["text.usetex"] (default: False) is False. Any string can be processed as Mathtext by placing the string inside a pair of dollar signs '$'. Mathtext often contains many backslashes '\'; so…
saved by
related reading
- 常用 LaTeX 數學符號指令 - HackMDhackmd.io
- Markdown 筆記 - HackMDhackmd.io
- Plots with different scales — Matplotlib 3.11.2 documentationmatplotlib.org
- Manual: math fontstype.today
- Pyplot tutorial — Matplotlib 3.11.0 documentationmatplotlib.org
- Lil'Loglilianweng.github.io
- Varun Shenoyvarunshenoy.com
- latex - Is it possible to render TeX math comments in VS Code? - Stack Overflowstackoverflow.com
- GitHub - Experience-Monks/math-as-code: a cheat-sheet for mathematical notation in code formgithub.com
- Leonard Tang.leonardtang.me
- The Architecture of Open Source Applications (Volume 2)matplotlibaosabook.org
- LaTeX.css — Make your website look like a LaTeX documentlatex.vercel.app