如何使 Matplotlib 输出中的字体与 LaTex 输出中的字体一致?


若要加粗 Matplotlib 中 LaTeX 坐标轴标签的字体,我们可以执行以下步骤:-

  • 为 x 创建数据点。
  • y, 即,y = sin(x) 创建数据点。
  • 使用 LaTex 展示 x 和 y 曲线。
  • 若要激活标签,请使用 legend() 方法。
  • 若要展示图,请使用 show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt, font_manager as fm
fprop = fm.FontProperties(fname='/usr/share/fonts/truetype/malayalam/Karumbi.ttf')
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(1, 10, 1000)
y = np.sin(x)
plt.plot(x, y, label=r'$\sin (x)$', c="red", lw=2)
plt.title(label=r'$\sin (x)$', fontproperties=fprop)
plt.show()

输出

更新于:15-May-2021

233 次浏览

职业快速入门

通过完成课程获得认证

开始
广告
© . All rights reserved.