带有乳胶的轴刻度标签的无衬线字体

2022-01-24 00:00:00 python matplotlib latex

问题描述

我第一次尝试将 Latex 与 matplotlib 一起使用.似乎在使用 Latex matplotlib 时,轴标签使用了衬线字体.我尝试使用

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')

但这没有效果,我假设这是因为轴标签位于数学环境中.有没有办法设置rc",以便 matplotlib 为轴标签使用无衬线字体?

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?

谢谢!


解决方案

在 sfmath 包.要在 matplotlib 中使用这个包,您需要更改它用于编译文本的 LaTeX 前导码,这可以通过 'text.latex.preamble' rc 选项来完成.因此,

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}')

应该做你想做的.您还可以选择另一种字体并将其作为选项提供给包,请参阅 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.

相关文章