Để vẽ đường line trong Matplotlib với khoảng tin cậy tại mỗi điểm dữ liệu, chúng ta có thể thực hiện các bước sau:
- Thiết lập kích thước figure và điều chỉnh padding giữa và xung quanh subplots.
- Tạo mảng means và standard deviations.
- Vẽ means bằng phương thức plot().
- Tô màu vùng giữa means+stds và means-stds, alpha=0.7 và color='yellow'.
- Để hiển thị figure, dùng phương thức 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 means = np.array([3, 5, 1, 8, 4, 6]) stds = np.array([1.3, 2.6, 0.78, 3.01, 2.32, 2.9]) plt.plot(means, color='red', lw=7) plt.fill_between(range(6), means - stds, means + stds, alpha=.7, color='yellow') plt.show()
Kết quả

