Matplotlib – Python繪圖中插入度數符號的方法?


要將度數符號插入繪圖中,我們可以使用LaTeX表示法。

步驟

  • 使用numpy建立pV、nR和T的資料點。
  • 使用plot()方法繪出pV和T。
  • 使用xlabel()方法為pV設定xlabel
  • 使用ylabel()方法為溫度標籤設定度數符號。
  • 要顯示該影像,請使用show()方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
pV = np.array([3, 5, 1, 7, 10, 9, 4, 2])
nR = np.array([31, 15, 11, 51, 12, 71, 41, 13])
T = np.divide(pV, nR)
plt.plot(pV, T, c="red")
plt.xlabel("Pressure x Volume")
plt.ylabel("Temperature ($^\circ$C)")
plt.show()

輸出

更新時間: 2021年5月6日

10K+瀏覽

開啟您的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.