带有 lualatex 的 matplotlib pgf 后端 - 非数学字体不会改变

问题描述

我有时需要 lualatex 引擎使用 matplotlib 的 pgf 后端,当产生像 hexbin 这样的“更重”的图时,否则超出 TeX 内存并且 pdflatex 失败。使用 lualatex 时,数学字体似乎根据我的 pgf.preamble 发生变化,但是字体的其余部分没有变化,并且保持为 CM Roman。使用 pdflatex,字体表现得如我所愿。请注意,如果我转到 www.overleaf.com 并使用相同的前导码并使用 pdflatexlualatex 进行编译,文档会显示我想要的字体,包括数学和正文。

使用lua引擎:

enter image description here

使用 pdf 引擎:

enter image description here

代码

import matplotlib as mpl

eng = 'lua' # issue with lua only   <<<<<<<<
# eng = 'pdf' # no issue here

mpl.use('pgf')
mpl.rc('font',family='serif')
mpl.rcParams.update({
        "pgf.rcfonts"  : False,"pgf.texsystem": eng + "latex","pgf.preamble" : '\\usepackage[utf8x]{inputenc}\\usepackage[light]{kpfonts}',})

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0,6,100)
x = np.sin(t)

fig,ax = plt.subplots()
ax.plot(t,x,label='A line')
plt.title('A function,$f(x) = \sin(x)$')
plt.legend()
plt.savefig('example.pdf')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)