Sans-serif Font for Axes Tick-labels with 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.
这篇关于带有乳胶的轴刻度标签的无衬线字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有乳胶的轴刻度标签的无衬线字体


基础教程推荐
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01