如何使用 Matplotlib 绘制包含两个汇总统计数据的箱线图?

How to plot a box plot with two summary statistics using Matplotlib?

我有我的数据的汇总统计信息:

Summary 1: min = 0, 1st quarter = 5, median = 200, mean = 455, 3rd quarter = 674, max = 980

Summary 2: min = 1, 1st quarter = 7.5, median = 254, mean = 586, 3rd quarter = 851, max = 1021

我想通过并排绘制摘要 1 和 2,使用 matplotlib 从这些统计数据中绘制箱线图。

我可以分别为每个摘要绘制图表(箱形图)(两个图表),但无法在单个图中绘制。

我在单独的箱形图中使用以下代码:

import matplotlib.pyplot as plt

stats = [{
    "label": 'Summary 1',  # not required
    "mean":  455,  # not required
    "med": 200,
    "q1": 5,
    "q3": 674,
    "whislo": 0,  # required (min)
    "whishi": 980,  # required (max)
    "fliers": []  # required if showfliers=True
    }]


fs = 10  # fontsize

fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(6, 6), sharey=True)
axes.bxp(stats)
axes.set_title('Boxplot for Summary 1', fontsize=fs)
plt.show()  

谁能告诉我该怎么做?

提前致谢!

查看the source code of the example on the matplotlib docsstats的值,需要将它们都放入同一个列表中。

import matplotlib.pyplot as plt

stats = [{
    "label": 'Summary 1',  # not required
    "mean":  455,  # not required
    "med": 200,
    "q1": 5,
    "q3": 674,
    "whislo": 0,  # required (min)
    "whishi": 980,  # required (max)
    "fliers": []  # required if showfliers=True
    },
         {
    "label": 'Summary 2',  # not required
    "mean":586,  # not required
    "med": 254,
    "q1": 7.5,
    "q3": 851,
    "whislo": 1,  # required (min)
    "whishi": 1021,  # required (max)
    "fliers": []  # required if showfliers=True
    }]


fs = 10  # fontsize

fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(6, 6), sharey=True)
axes.bxp(stats)
axes.bxp(stats)
axes.set_title('Boxplot for Summary 1', fontsize=fs)
plt.show()