0

I want to use Times New Roman font with my matplotlib plots. I'm currently using matplotlib-3.5.1 and I have fonttools-4.28.5 installed. However, when I try:

plt.rcParams["font.family"] = "Times New Roman"

The font doesn't change. I then found a recommendation to instead try:

plt.rcParams["font.family"] = "DejaVu Serif"
plt.rcParams["font.serif"] = ["Times New Roman"]

This also had no effect. What am I doing wrong and how do I fix it?

I already looked at other posts e.g. 1, 2 to no avail.

Edit: Following this post, it appears that matplotlib doesn't have Times New Roman?

['C059', 'C059', 'C059', 'C059', 'D050000L', 'DejaVu LGC Sans Mono', 'DejaVu LGC Sans Mono', 'DejaVu LGC Sans Mono', 'DejaVu LGC Sans Mono', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans Display', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Serif', 'DejaVu Serif', 'DejaVu Serif', 'DejaVu Serif', 'DejaVu Serif Display', 'Liberation Mono', 'Liberation Mono', 'Liberation Mono', 'Liberation Mono', 'Nimbus Mono PS', 'Nimbus Mono PS', 'Nimbus Mono PS', 'Nimbus Mono PS', 'Nimbus Roman', 'Nimbus Roman', 'Nimbus Roman', 'Nimbus Roman', 'Nimbus Sans', 'Nimbus Sans', 'Nimbus Sans', 'Nimbus Sans', 'Nimbus Sans Narrow', 'Nimbus Sans Narrow', 'Nimbus Sans Narrow', 'Nimbus Sans Narrow', 'P052', 'P052', 'P052', 'P052', 'STIX', 'STIX', 'STIX', 'STIX', 'STIX Math', 'STIXGeneral', 'STIXGeneral', 'STIXGeneral', 'STIXGeneral', 'STIXNonUnicode', 'STIXNonUnicode', 'STIXNonUnicode', 'STIXNonUnicode', 'STIXSizeFiveSym', 'STIXSizeFourSym', 'STIXSizeFourSym', 'STIXSizeOneSym', 'STIXSizeOneSym', 'STIXSizeThreeSym', 'STIXSizeThreeSym', 'STIXSizeTwoSym', 'STIXSizeTwoSym', 'URW Bookman', 'URW Bookman', 'URW Bookman', 'URW Bookman', 'URW Gothic', 'URW Gothic', 'URW Gothic', 'URW Gothic', 'Z003', 'cmb10', 'cmex10', 'cmmi10', 'cmr10', 'cmss10', 'cmsy10', 'cmtt10']
Rylan Schaeffer
  • 1,945
  • 2
  • 28
  • 50

1 Answers1

4

Following https://matplotlib.org/stable/gallery/text_labels_and_annotations/font_family_rc_sgskip.html?highlight=font#configuring-the-font-family, this should work:

plt.rcParams["font.family"] = "serif"
plt.rcParams["font.serif"] = ["Times New Roman"]
Gabriele
  • 420
  • 4
  • 15