如何使 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()
輸出

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP