Python 繪圖中的上標
要在 Python 中放置某個上標,我們可以採取以下步驟 -
使用 numpy,為 a 和 f 建立點。
使用 plot() 方法,用標籤 f=ma 繪製 f = ma 曲線。
使用上標為該繪圖新增標題,即 kgms-2。
使用上標為該繪圖新增 xlabel,即 ms-2。
使用上標為該繪圖新增 ylabel,即 kg。
要放置圖例,請使用 legend() 方法。
要顯示圖形,請使用 show() 方法。
範例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True a = np.linspace(1, 10, 100) m = 20 f = m*a plt.plot(a, f, c="red", lw=5, label="f=ma") plt.title("Force $\mathregular{kgms^{-2}}$") plt.xlabel("Acceleration $\mathregular{ms^{-2}}$") plt.ylabel("Acceleration $\mathregular{kg}$") plt.legend() plt.show()
輸出
廣告