Để hiển thị điểm trung bình (mean) trên box plot, thiết lập showmeans=True trong phương thức boxplot().
Các bước
- Thiết lập figure size và autolayout.
- Tạo dữ liệu ngẫu nhiên (100x5).
- Tạo figure và axes.
- Vẽ boxplot với showmeans=True (ký hiệu 'd' cho diamond marker).
- Hiển thị bằng show().
Ví dụ
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
data = np.random.rand(100, 5)
fig = plt.figure()
ax = fig.add_subplot(111)
bp = ax.boxplot(data, 'd', showmeans=True)
plt.show()
Kết quả
