如何使用Matplotlib在X轴下添加脚注?
要在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, "脚注:y=e^{x}", ha="center", fontsize=18, bbox={"facecolor": "green", "alpha": 0.75, "pad": 5})
plt.show()