0

I am trying to use a different font for plots, there are many answers on this but none of them seem to work. In all cases, there is no error, and the default font is used indifferent to my choice. Here are some things I've tried:

  1. Changing globally
from matplotlib import pyplot as plt

plt.rcParams["font.family"] = "Times New Roman" 
plt.title('Title')
plt.show()
  1. Changing "locally"
csfont = {'fontname': 'Times New Roman'}
plt.title('Title', **csfont)
plt.show()

  1. Updating params (the other parameters in params update just fine here)
params = {'axes.labelsize': 18, 'axes.titlesize': 20, 'font.family': 'Times New Roman', 'legend.fontsize': 20, 'xtick.labelsize': 28, 'ytick.labelsize': 40}
plt.rcParams.update(params)
plt.title('Title')
plt.show()

This is driving me crazy, any ideas are greatly appreciated.

Edit:

I checked which fonts I have by doing

matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')"

I don't think I see fonts like Times New Roman, Helvetica, etc. in here. But when I take one from this list, (e.g. NotoSerifHebrew-Regular), I get a warning

findfont: Font family ['NotoSerifHebrew-Regular'] not found. Falling back to DejaVu Sans. 

But when I run the same line again, I no longer get this warning

PhysicsPerson
  • 21
  • 1
  • 5
  • All three of these work just fine, with the typos removed (`plt` instead of `matplotlib` and no need for `;`) - what behaviour are you seeing and what did you expect? Are you using fonts that you actually have installed? What platform are you on? (OS, Python version, matplotlib version) – Grismar Sep 07 '22 at 23:16
  • @Grismar I expect the fonts to change on my title, and instead what I see is that the font is always the default. I haven't checked what fonts are installed, but I assume I have Arial, Comic Sans MS, Helvetica, etc. I've tried all of these and none show up on the title. I am on Ubuntu, python 3.8.5, and matpotlib3.3.2 – PhysicsPerson Sep 07 '22 at 23:23

1 Answers1

1

Okay found the answer from this post: [https://stackoverflow.com/questions/42097053/matplotlib-cannot-find-basic-fonts/49884009#49884009][1]

I was on jupyter notebook, so many of the common solutions were not working. I'll copy the jupyter specific solution here:

1-Stopping Jupyter

2-Installing font-manager: sudo apt install font-manager

3-Cleaning the matplotlib cache directory: rm ~/.cache/matplotlib -fr

4-Restarting Jupyter.

PhysicsPerson
  • 21
  • 1
  • 5