1"""
2===================================
3Using a ttf font file in Matplotlib
4===================================
5
6Although it is usually not a good idea to explicitly point to a single ttf file
7for a font instance, you can do so using the `font_manager.FontProperties`
8*fname* argument.
9
10Here, we use the Computer Modern roman font (``cmr10``) shipped with
11Matplotlib.
12
13For a more flexible solution, see :doc:`/gallery/api/font_family_rc_sgskip` and
14:doc:`/gallery/text_labels_and_annotations/fonts_demo`.
15"""
16
17import os
18from matplotlib import font_manager as fm, rcParams
19import matplotlib.pyplot as plt
20
21fig, ax = plt.subplots()
22
23fpath = os.path.join(rcParams["datapath"], "fonts/ttf/cmr10.ttf")
24prop = fm.FontProperties(fname=fpath)
25fname = os.path.split(fpath)[1]
26ax.set_title('This is a special font: {}'.format(fname), fontproperties=prop)
27ax.set_xlabel('This is the default font')
28
29plt.show()
30