Để thêm footnote (chú thích chân trang) dưới trục X, dùng plt.figtext(x, y, text, ...) với tọa độ figure fraction (0-1) và bbox decoration.
Các bước
- Thiết lập figure size và autolayout.
- Tạo dữ liệu và vẽ biểu đồ.
- Thêm footnote: plt.figtext(0.5, 0.01, "footnote: $y=e^{x}$", ha="center", fontsize=18, bbox={"facecolor": "green", "alpha": 0.75, "pad": 5}).
- Hiển thị bằng show().
Ví dụ
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()
Kết quả
