LaTeX Formatting

Scientific publications require equations and text in graphs to be formatted in LaTex.

For LaTex formatting in matplotlib, use dollar signs to encapsulate LaTeX in any text.

In LaTeX, we use the backslash in commands for special symbols and Greek letters: for example, \lambda to produce the symbol λ\lambda. But the backslash already has a meaning in Python strings: it is the escape code character. To avoid Python messing up our LaTeX code, we need to use raw text strings.

Raw text strings are prepended with an ‘r’, like r"\lambda" or r’\lambda’ instead of "\lambda" or ’\lambda’. Let’s look at an example of this below:

Get hands-on with 1200+ tech skills courses.