Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib not listening to font choices

I am unable to avoid an error in matplotlib regarding font choice. Whenever I try to plot on a remote machine in Linux I get the following error:

/home/josh/anaconda/envs/py27/lib/python2.7/site-packages/matplotlib/font_manager.py:1236:
UserWarning: findfont: Font family ['Arial'] not found. 
Falling back to Bitstream Vera Sans 
(prop.get_family(), self.defaultFamily[fontext]))

I have edited my .matplotlibrc file (just in case, in two locations):

  • .matplotlib/.matplotlibrc
  • .config/matplotlib/.matplotlibrc

Where I added the following lines:

backend: Agg
font.family        : serif
font.serif         : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman
font.sans-serif    : Helvetica, Avant Garde, Computer Modern Sans serif
font.cursive       : Zapf Chancery
font.monospace     : Courier, Computer Modern Typewriter
text.usetex        : true

Still, matplotlib keeps complaining about Arial. Why? (note this is when running a script with python my_script.py) with no IPython involved.

like image 660
Amelio Vazquez-Reina Avatar asked Apr 21 '14 23:04

Amelio Vazquez-Reina


2 Answers

If you're using seaborn and don't have Arial installed, this will happen (I'm actually currently in the process of making this work better). Best solution for the time being would be to call

sns.set(font="serif")

After importing seaborn and before plotting.

like image 133
mwaskom Avatar answered Sep 17 '22 17:09

mwaskom


from the documentation (see method description for set_family or set_name)

Real font names are not supported when text.usetex is True.

Perhaps you should use a font family like 'serif', 'sans-serif', 'cursive', 'fantasy', or 'monospace' if you'd like to be able to use TeX.

like image 32
akgill Avatar answered Sep 21 '22 17:09

akgill