I have a custom font file (ttf) I would like to use with matplotlib. I
don't have sudo access, so can't just add it to the standard fonts
directory, but would like to add it to matplotlib's list of known fonts.
I know that I can do something like this for one-off uses:
from matplotlib import font_manager
fp = font_manager.FontProperties(fname='myfont.ttf')
fig = pyplot.figure()
ax = fig.gca()
ax.plot([1, 2, 3, 4, 5])
ax.set_xlabel('X-axis label', fontproperties=fp)
But I would like to use the font as the default for all text objects in my
figure. I have tried using rcParams:
rcParams['font.family'] = fp.get_family()
rcParams['font.sans-serif'] = fp.get_name()
but I get the standard warning:
UserWarning: findfont: Font family [u'sans-serif'] not found. Falling back
to Bitstream Vera Sans
and it uses the default font, even after blowing away my fontList.cache
file (many times). I suspect that I have loaded the font using the
FontProperties object, but haven't actually 'registered' it with matplotlib
so it knows what to do when I specify the font name, or something like that.
Any help would be great.
duncan.macleod at ligo.org
LIGO Data Grid systems development
Louisiana State University
-------------- next part --------------
An HTML attachment was scrubbed...