use format with tex fraction expression in matplotlib python

You need to escape the curled brackets ({) with another curled bracket. r’$\frac{{{}}}{{8}}$’.format(i) Here the inner most bracket pair in {{{}}} is used for formatting. The escape pair {{ is replaced by a single bracket during formatting. Hence r’$\frac{{{}}}{{8}}$’.format(1) will result in r’$\frac{1}{8}$’, which is then a valid MathText string.

Python: Unable to Render Tex in Matplotlib

On an Ubunutu 14.04 machine the combination of answers from above worked. I sudo apt-get install the dvipng,texlive-latex-extra, and texlive-fonts-recommended packages and that did the trick: $ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended Edit: As of Matplotlib 3.2.1, you now also need the package cm-super (see https://github.com/matplotlib/matplotlib/issues/16911) $ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended cm-super