Bold font weight for LaTeX axes label in matplotlib
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}"]
In case anyone stumbles across this from Google like I did, another way that doesn't require adjusting the rc preamble (and conflicting with non-latex text) is:
ax.set_ylabel(r"$\mathbf{\partial y / \partial x}$")
If you intend to have consistently bolded fonts throughout the plot, the best way may be to enable latex and add \boldmath
to your preamble:
# Optionally set font to Computer Modern to avoid common missing font errors
matplotlib.rc('font', family='serif', serif='cm10')
matplotlib.rc('text', usetex=True)
matplotlib.rcParams['text.latex.preamble'] = [r'\boldmath']
Then your axis or figure labels can have any mathematical latex expression and still be bold:
plt.xlabel(r'$\frac{\phi + x}{2}$')
However, for portions of labels that are not mathematical, you'll need to explicitly set them as bold:
plt.ylabel(r'\textbf{Counts of} $\lambda$'}