Bold and italic label of axis

How to write this x in xlabel bold and italic?

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties    

plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"]
params = {'text.usetex' : True,
          'font.size' : 14,
          'font.family' : 'lmodern',
          'text.latex.unicode': True,
          }
plt.rcParams.update(params)

fig, ax = plt.subplots()

    ax.annotate('x', xy=(0.93, -0.01), ha='left', va='top', xycoords='axes fraction', weight='bold', style='italic')

plt.show()

Adding of from matplotlib import rc does not help.

Answers

Using normal text

Use weight and style arguments:

ax.annotate("x", ..., weight='bold', style='italic')

Using Latex

i.e. when rcParams["usetex"] = True,

ax.annotate(r'\textbf{\textit{x}}', ...)

as seen e.g. in correct-way-to-bold-italicize-text

Posted on by ImportanceOfBeingErnest

Relevant tags