习题 9.3

1.代码实现

点击查看代码
import matplotlib.pyplot as plt
data = [
    [4.13, 3.86, 4.00, 3.88, 4.02, 4.02, 4.00],
    [4.07, 3.85, 4.02, 3.88, 3.95, 3.86, 4.02],
    [4.04, 4.08, 4.01, 3.91, 4.02, 3.96, 4.03],
    [4.07, 4.11, 4.01, 3.95, 3.89, 3.97, 4.04],
    [4.05, 4.08, 4.04, 3.92, 3.91, 4.00, 4.10],
    [4.04, 4.01, 3.99, 3.97, 4.01, 3.82, 3.81],
    [4.02, 4.02, 4.03, 3.92, 3.89, 3.98, 3.91],
    [4.06, 4.04, 3.97, 3.90, 3.89, 3.99, 3.96],
    [4.10, 3.97, 3.98, 3.97, 3.99, 4.02, 4.05],
    [4.04, 3.95, 3.98, 3.90, 4.00, 3.93, 4.06]
]

labs = ['Lab1', 'Lab2', 'Lab3', 'Lab4', 'Lab5', 'Lab6', 'Lab7']
data_transposed = list(zip(*data))

plt.figure(figsize=(10, 6))
plt.boxplot(data_transposed, labels=labs)
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
plt.title('各实验室测量结果的箱线图')
plt.xlabel('实验室')
plt.ylabel('测量值')
plt.grid(True)
plt.show()

2.运行结果

posted on 2024-11-26 17:41  克卜勒星球  阅读(8)  评论(0编辑  收藏  举报

导航