如何使 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.