matplotlib - matplotlib pgf 后端与 lualatex - 非数学字体不会改变
问题描述
在生成像 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')
解决方案
推荐阅读
- vue.js - 如何保持两个相同的 Vue 组件彼此同步?
- javascript - 切换到不同的加密库
- c# - 将装配体 A 中的 X 型铸造到装配体 B 中的 X 型
- python - swig python wrap c++ 指向多态类型的指针向量
- html - Bootstrap 4 全屏桌面 - 列填充剩余空间
- java - (Java) 满足某些条件时如何立即取消定时器
- angular - Angular 7 ngFor 迭代对象数组
- parsing - HAR 文件读取错误:log.entries 应为数组
- swift - Swif / Cocoa / MacOS - 如何停止发送密钥
- swift - 与擦除类型的可编码一致性?