在 matplotlib 中使用 Latex 时如何将字体系列设置为 "erewhon"?

How to set a font family to "erewhon" when using Latex in matplotlib?

我在我的一些绘图中使用乳胶格式作为轴标签和轴刻度标签。我的问题是 Latex 字体不同于 'erewhon' 的非 Latex 字体。所以想尝试使用latex格式的'erewhon'。

我尝试了多种方法,例如以下代码:

fig, ax1 = plt.subplots(figsize = (8,5))

rcParams = [{'text.usetex': True,
         'svg.fonttype': 'none',
         'text.latex.preamble': r'\usepackage{erewhon}',
         'font.size': 20,
         'font.family': 'erewhon',
         'mathtext.fontset': 'custom',
         'mathtext.rm': 'erewhon',
         'mathtext.it': 'erewhon',
         'mathtext.bf': 'erewhon'}]


xlabel='Oxygen mass flow (sccm)'
ylabel1=r'$\mathrm{\rho \; (\mu \Omega \cdot cm)}$'

ax1.semilogy(xfit, ( np.exp(m*xfit+b) ) , 'k-', lw=2)
ax1.set_yscale('log')

ax1.set_xlabel(xlabel, fontsize=20)
ax1.set_ylabel(ylabel1, fontsize=20)

此代码提供的 xlabel 字体为 'erewhon' 但 ylabel 仍然使用任何字体(我什至不知道是哪一种),尽管我使用 \mathrm{}。这个问题有什么解决办法吗? 感谢您的帮助!

此处应用 Ralf Stubner 的 ,此代码

import matplotlib.pyplot as plt

preamble = [r"\usepackage[proportional,scaled=1.064]{erewhon}", 
            r"\usepackage[erewhon,vvarbb,bigdelims]{newtxmath}", 
            r"\usepackage[T1]{fontenc}",
            r"\renewcommand*\oldstylenums[1]{\textosf{#1}}"]

rcParams = {'text.usetex': True,
         'svg.fonttype': 'none',
         'text.latex.preamble': preamble,
         'font.size': 20,
         'font.family': 'erewhon'}
plt.rcParams.update(rcParams)

fig, ax1 = plt.subplots(figsize = (8,5))



xlabel='Oxygen mass flow (sccm)'
ylabel1=r'$\mathrm{\rho \; (\mu \Omega \cdot cm)}$'

#ax1.semilogy(xfit, ( np.exp(m*xfit+b) ) , 'k-', lw=2)
ax1.set_yscale('log')

ax1.set_xlabel(xlabel, fontsize=20)
ax1.set_ylabel(ylabel1, fontsize=20)

plt.tight_layout()
plt.show()

生产