在生成像 hexbin 这样的“更重”图时,我有时需要lualatex
引擎使用 matplotlib 的 pgf 后端,否则会超出 TeX 内存并pdflatex
失败。使用lualatex
数学字体时,似乎会根据我pgf.preamble
的 . 使用pdflatex
,字体表现出我想要的样子。请注意,如果我访问www.overleaf.com并使用相同的序言并使用pdflatex
or进行编译lualatex
,该文档会在数学和正文中显示我想要的字体。
代码:
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')