【发布时间】:2019-05-12 11:00:26
【问题描述】:
我知道任何字符串都可以在 matplotlib 和 plotly 中使用 LaTeX 渲染。例如,r$\sqrt{\dfrac{m\sigma^2}{\epsilon}}$ 将给出正确的如下图链接。
但是,我想使用 Arial 等普通字体,而不是默认的 LaTeX 字体。有什么办法可以做到吗?
【问题讨论】:
标签: python matplotlib plotly
我知道任何字符串都可以在 matplotlib 和 plotly 中使用 LaTeX 渲染。例如,r$\sqrt{\dfrac{m\sigma^2}{\epsilon}}$ 将给出正确的如下图链接。
但是,我想使用 Arial 等普通字体,而不是默认的 LaTeX 字体。有什么办法可以做到吗?
【问题讨论】:
标签: python matplotlib plotly
您可以尝试将字体关键字传递给标签函数或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]:
【讨论】: