Sans-serif Font for Axes Tick-labels with Latex

别说谁变了你拦得住时间么 提交于 2019-12-12 16:23:31

问题


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:


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.



来源:https://stackoverflow.com/questions/11611374/sans-serif-font-for-axes-tick-labels-with-latex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!