如何用 matplotlib 打印摄氏度符号?


要在 matplotlib 中打印摄氏度符号,我们可以采取以下步骤 −

  • 设定图形大小,调整子图之间和周围的填充。
  • 初始化变量 N
  • 使用 numpy 创建 TP 数据点。
  • 使用 plot() 方法绘制 TP
  • 设置 X 轴标签。
  • 使用 show() 方法显示图像。

示例

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

N = 10
T = np.random.rand(N)
P = np.random.rand(N)

plt.plot(T, P)
plt.xlabel("$Temperature {^\circ}C$")

plt.show()

输出

更新于:2021 年 6 月 10 日

872 次浏览

开启 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.