Change Font Type Of Some Letters In A Word In A Matplotlib Plot
Say, for example, this is the plot I want to make with 'L' in 'LEGEND' in a different font. import matplotlib.pyplot as plt plt.plot([1,2,3],[4,5,6]) plt.legend(['LEGEND']) plt.sh
Solution 1:
Note that unless you use usetex=True
, you will not be using latex, but rather matplotlib's mathtext.
This allows you to use different kind of modifications to the font, the same known from latex, like \mathit
for italic text etc.
You might hence opt for something like
ax.legend(['$\mathcal{L}\mathrm{EG}\mathit{END}$'], prop={'size':14})
Using true latex rendering may actually help you more here, because it would in prinpicle allow to use as many different fonts as you wish.
import matplotlib.pyplot as plt
plt.rcParams['text.usetex'] = True
plt.rcParams['text.latex.preamble'] = [
r'\usepackage[T1]{fontenc}',
r'\usepackage{cyklop}' ]
fig, ax=plt.subplots()
ax.plot([1,1,1,1,10])
tx = r'{\fontfamily{cyklop}\selectfont L}' + \
r'{\fontfamily{bch}\selectfont E}' + \
r'{\fontfamily{phv}\selectfont G}' + \
r'{\fontfamily{lmtt}\selectfont END}'
ax.legend([tx], prop={'size':14})
plt.show()
Post a Comment for "Change Font Type Of Some Letters In A Word In A Matplotlib Plot"