Matplotlib boxplot using precalculated (summary) statistics

前端 未结 3 1016
抹茶落季
抹茶落季 2020-12-14 10:13

I need to do a boxplot (in Python and matplotlib) but I do not have the original \"raw\" data. What I have are precalculated values for max, min, mean, median and IQR (norma

3条回答
  •  青春惊慌失措
    2020-12-14 10:36

    Referring to the answer of @MKroehnert and Boxplot drawer function at https://matplotlib.org/gallery/statistics/bxp.html, the following could be helpful:

    import matplotlib.pyplot as plt
    
    stats = [{
        "label": 'A',  # not required
        "mean":  5,  # not required
        "med": 5.5,
        "q1": 3.5,
        "q3": 7.5,
        # "cilo": 5.3 # not required
        # "cihi": 5.7 # not required
        "whislo": 2.0,  # required
        "whishi": 8.0,  # required
        "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 precalculated statistics', fontsize=fs)
    plt.show()
    

提交回复
热议问题