Matplotlib – 如何在 Python 图中插入度数符号?
pythonmatplotlibserver side programmingprogramming更新于 2025/3/26 13:00:17
要将度数符号插入图中,我们可以使用 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()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

