There have been many threads on this already (Force matplotlibrc to use Arial (path of font), How to load .ttf file in matplotlib using mpl.rcParams?). None seems to help in my case. I have number of fonts installed on my system and registered in matplotlib. Everything seems to work when I am in the shell:
>>> import matplotlib as mpl
>>> from matplotlib import font_manager
>>> path = '/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf'
>>> props = font_manager.FontProperties(fname=path)
>>> print props
family=Times New Roman ... file=/usr/.../Times_New_Roman.ttf ...
>>> mpl.rcParams['font.family'] = props.get_name()
>>> mpl.rcParams
RcParams({...,u'font.family': [u'Times New Roman'], ... })
However, when I try to do the same in a script and run it (and I have tried a dozen times), I get:
/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:1282: UserWarning: findfont: Font family [u'Times New Roman'] not found.
Why?