3
votes

I'm trying to use Latex with matplotlib for the first time. It seems that when using Latex matplotlib uses a serif font for the axes labels. I tried explicitly setting the font-family to 'sans-serif' using

rc('font',family='sans-serif')

but this had no effect, I'm assuming this is because the axes-labels are inside a math-environment. Is there a way to set the 'rc' so that matplotlib will use a sans-serif font for the axes labels?

Thanks!

1

1 Answers

10
votes

Sans-serif math fonts can be used in LaTeX with the help of the sfmath package. To use this package in matplotlib, you need to alter the LaTeX preamble it uses to compile text, which can be done through the 'text.latex.preamble' rc option. Hence,

rc('text.latex', preamble='\usepackage{sfmath}')

should do what you want. You can also choose another font and supply it as an option to the package, see sfmath's documentation for reference.