我知道任何字符串都可以在 matplotlib 和 plotly 中使用 LaTeX 呈现。例如,r$\sqrt{\dfrac{m\sigma^2}{\epsilon}}$
将给出正确的如下图链接。
但是,我想使用普通字体(例如 Arial)而不是默认的 LaTeX 字体。有什么办法可以做到吗?
您可以尝试将字体关键字传递到标签函数或传递到matplotlib.rc
:
In [1]:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
x = np.linspace(0, 4*np.pi)
y = 2 * np.sin(np.exp(3/2*x))
fontspecs = {'family': 'Arial',
'weight': 'bold'}
mpl.rc('font', **fontspecs) # To set font-specifications globally
plt.plot(x, y)
plt.xlabel(r'$2 * sin(e^{\frac{3}{2} * x})$')
# plt.xlabel(r'$2 * sin(e^{\frac{3}{2} * x})$', # To just use font settings for this label
# fontname=fontspecs['family'], fontweight=fontspecs['weight'])
Out [1]:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句