None of the answers above solved the issue for me. After trying and failing, this solved the issue. It works as of July 2024 with matplotlib 3.7.1. The program is for running in Google Colab. A notebook with the solution is here. Colab notebook
import matplotlib as mpl
import matplotlib.font_manager as fm
print(mpl.__version__)
!wget -O TimesNewRoman.ttf https://github.com/justrajdeep/fonts/raw/master/Times%20New%20Roman.ttf
font_dirs = ["/content/"]
font_files = fm.findSystemFonts(fontpaths=font_dirs, fontext='ttf')
for font_file in font_files:
print(font_file) if 'TimesNewRoman' in font_file else None
fm.fontManager.addfont(font_file)
Then, trying to plot using Times New Roman font
import matplotlib.pyplot as plt
plt.rcParams['font.serif'] = "Times New Roman"
plt.rcParams['font.family'] = "serif"
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 3, 5]
plt.plot(x, y)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Simple Plot")
plt.show()