0

I would like to use the Latex font in my Matplotlib diagrams. On Windows I have set the the system environment variable PATH to include the paths to MikTex's bin\x64 folder, where the latex and dvipdf and dvipng scripts are located and to Ghostscripts GS\BIN folder.

However when I am trying to use the Latex font like this

from matplotlib import rc

rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)

I get an error message that the font was not found:

...\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1331: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

I also tried deleting the Matplotlib cache, but I still get the same error.

What did I forget to do or what am I getting wrong here?

Axel
  • 1,415
  • 1
  • 16
  • 40
  • See my (admittedly old, hopefully not outdated) answer here: https://stackoverflow.com/questions/2537868/sans-serif-math-with-latex-in-matplotlib/20709149#20709149 . I think you need to work on a latex preamble. According to a comment on the post, specifically you need `\usepackage{helvet}` – Paul H Oct 20 '20 at 14:21
  • Hi @PaulH, thanks for your comment! I now tried all of the three answers to other question (yours of course first ;-)), but I still get the `Font family ['sans-serif'] not found.` error. Do you have any other idea what could cause this issue? – Axel Oct 20 '20 at 16:03
  • is the font family simply "sans"? – Paul H Oct 20 '20 at 16:09
  • (btw, with my old answer, you don't need to set the family) – Paul H Oct 20 '20 at 16:10
  • I think the main issue was that I forgot to reset the rc settings using `mpl.rcParams.update(mpl.rcParamsDefault)` so some previous issue kept messing up the whole thing. – Axel Oct 20 '20 at 16:35

0 Answers0