如何使用 Matplotlib 在 X 轴下添加脚注?
matplotlibpythondata visualization更新于 2025/6/2 22:04:17
要使用 matplotlib 在 X 轴下添加脚注,我们可以使用 figtext() 和 text() 方法。
步骤
- 设置图形大小并调整子图之间和周围的填充。
- 使用 numpy 创建 x 和 y 数据点。
- 使用 numpy 绘制 x 和 y 数据点。
- 要放置脚注,请使用带有 x、y 位置和 box 属性的 figtext() 方法。
- 要显示图形,请使用 show() 方法。
示例
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-2, 2, 100)
y = np.exp(x)
plt.plot(x, y)
plt.figtext(0.5, 0.01, "footnote: $y=e^{x}$", ha="center", fontsize=18, bbox={"facecolor": "green", "alpha": 0.75, "pad": 5})
plt.show()
输出

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

