I'm trying to generate figures using matplotlib
in which all of the text is sans-serif (Open Sans) by default. A number of questions here on SO, along with the Open Sans documentation, suggest something like
matplotlib.rc('text', usetex=True)
matplotlib.rcParams['text.latex.preamble'] = [
r'\usepackage[default,scale=0.85]{opensans}'
]
should work, but instead I see the serif font. For example, the above uses what looks like Computer Modern, and
matplotlib.rcParams['text.latex.preamble'] = [
r'\usepackage[charter,expert,euro]{mathdesign}',
r'\usepackage[default,scale=0.85]{opensans}'
]
uses Charter. Adding something like \renewcommand{\familydefault}{\sfdefault}
has no effect.
How do I force matplotlib
using LaTeX, to use a specified sans-serif font by default for all text (axes, labels, annotations, etc.)?
FWIW, when I don't use LaTeX (text.usetex=False
) I don't get Open Sans as expected either, but I do get the sans-serif. For example
font = {'family': 'sans-serif', 'sans-serif': ['Open Sans','sans-serif']}
plt.rc('font', **font)
results in a sans-serif font that's not Open Sans. I have no problems with Open Sans in other tools or applications, including LaTeX/TeX tools.