Sans-serif字体,用于带有乳胶的轴刻度标签 [英] Sans-serif Font for Axes Tick-labels with Latex
问题描述
我正在尝试将Latex与matplotlib一起使用.似乎在使用Latex时,matplotlib为轴标签使用了衬线字体.我尝试使用
将字体系列明确设置为"sans-serif"rc('font',family='sans-serif')
但是这没有效果,我假设这是因为轴标签位于数学环境内.有没有办法设置"rc",以便使matplotlib对轴标签使用sans-serif字体?
谢谢!
Sans-serif数学字体可以在 sfmath的文档以供参考. >
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!
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.
这篇关于Sans-serif字体,用于带有乳胶的轴刻度标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!