Search code examples
pythonmatplotliblatex

Bold font weight for LaTeX axes label in matplotlib


In matplotlib you can make the text of an axis label bold by

plt.xlabel('foo',fontweight='bold')

You can also use LaTeX with the right backend

plt.xlabel(r'$\phi$')

When you combine them however, the math text is not bold anymore

plt.xlabel(r'$\phi$',fontweight='bold')

Nor do the following LaTeX commands seem to have any effect

plt.xlabel(r'$\bf \phi$')
plt.xlabel(r'$\mathbf{\phi}$')

How can I make a bold $\phi$ in my axis label?


Solution

  • Unfortunately you can't bold symbols using the bold font, see this question on tex.stackexchange.

    As the answer suggests, you could use \boldsymbol to bold phi:

    r'$\boldsymbol{\phi}$'
    

    You'll need to load amsmath into the TeX preamble:

    matplotlib.rc('text', usetex=True)
    matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]