如何在使用 Matplotlib 的情况下在 X 轴下方添加脚注?


若要使用 matplotlib 在 X 轴下方添加脚注,我们可以使用 figtext()text() 方法。

步骤

  • 设置图形大小并调整子图之间和周围的填充。
  • 使用 numpy 创建 x 和 y 数据点。
  • 使用 numpy 绘制 x 和 y 数据点。
  • 为放置脚注,使用 figtext() 方法,其中包含 x 和 y 位置以及 box 属性。
  • 为显示图形,使用 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()

输出

更新时间:02-Jun-2021

2K+ 浏览量

开启 职业生涯

学习课程,获取认证

开始学习
广告
© . All rights reserved.