Matplotlib 字体与 LaTeX 常用字体
Matplotlib font common font with LaTeX
我似乎无法为常规文本和数学数字设置相同的字体
我正在尝试使用 Matplotlib 为文章草稿设置字体,我需要使用的字体是 Libertine。理想情况下,我会让 LaTeX 完成所有格式设置,但似乎设置为使用现代计算机格式化数学字体:
import matplotlib as mpl
rc_fonts = {
"font.family": "serif",
"font.size": 20,
'figure.figsize': (5, 3),
"text.usetex": True,
'text.latex.preview': True,
'text.latex.preamble': [
r"""
\usepackage[libertine]{newtxmath}
\usepackage{libertine}
"""],
}
mpl.rcParams.update(rc_fonts)
import matplotlib.pylab as plt
加上琐碎的情节
plt.ion()
plt.clf()
plt.plot(range(10))
plt.title("something 0,2,4,6,8 $e=mc^2$")
产生(比较“2”)
如果我改用
rc_fonts = {
"font.family": "serif",
'font.serif': 'Linux Libertine O',
"font.size": 20,
'figure.figsize': (5, 3),
}
然后数字现在匹配但数学不使用 LaTeX(不出所料):
为了获得我从 https://ctan.org/tex-archive/install/fonts and installed them using the description from https://dallascard.github.io/changing-the-font-in-matplotlib.html (http://andresabino.com/2015/08/18/fonts-and-matplotlib/ 下载的 libertine 字体似乎相关)。以下问题似乎触及了这个问题,但我还无法从中找到解决方案:
- Matplotlib, Consistent font using latex
- how to set up a custom font with custom path to matplotlib global font?
基于, it seems this is not an issue with Matplotlib at all, but can be replicated by LaTeX using the preamble. Switching the order of the packages, which is the order as seen in answers to this question: https://tex.stackexchange.com/questions/544474/libertine-and-math-numbers则问题已解决:
rc_fonts = {
"font.family": "serif",
"font.size": 20,
'figure.figsize': (5, 3),
"text.usetex": True,
'text.latex.preview': True,
'text.latex.preamble': [
r"""
\usepackage{libertine}
\usepackage[libertine]{newtxmath}
"""],
}
给予
我似乎无法为常规文本和数学数字设置相同的字体
我正在尝试使用 Matplotlib 为文章草稿设置字体,我需要使用的字体是 Libertine。理想情况下,我会让 LaTeX 完成所有格式设置,但似乎设置为使用现代计算机格式化数学字体:
import matplotlib as mpl
rc_fonts = {
"font.family": "serif",
"font.size": 20,
'figure.figsize': (5, 3),
"text.usetex": True,
'text.latex.preview': True,
'text.latex.preamble': [
r"""
\usepackage[libertine]{newtxmath}
\usepackage{libertine}
"""],
}
mpl.rcParams.update(rc_fonts)
import matplotlib.pylab as plt
加上琐碎的情节
plt.ion()
plt.clf()
plt.plot(range(10))
plt.title("something 0,2,4,6,8 $e=mc^2$")
产生(比较“2”)
如果我改用
rc_fonts = {
"font.family": "serif",
'font.serif': 'Linux Libertine O',
"font.size": 20,
'figure.figsize': (5, 3),
}
然后数字现在匹配但数学不使用 LaTeX(不出所料):
为了获得我从 https://ctan.org/tex-archive/install/fonts and installed them using the description from https://dallascard.github.io/changing-the-font-in-matplotlib.html (http://andresabino.com/2015/08/18/fonts-and-matplotlib/ 下载的 libertine 字体似乎相关)。以下问题似乎触及了这个问题,但我还无法从中找到解决方案:
- Matplotlib, Consistent font using latex
- how to set up a custom font with custom path to matplotlib global font?
基于
rc_fonts = {
"font.family": "serif",
"font.size": 20,
'figure.figsize': (5, 3),
"text.usetex": True,
'text.latex.preview': True,
'text.latex.preamble': [
r"""
\usepackage{libertine}
\usepackage[libertine]{newtxmath}
"""],
}
给予