Matplotlib boxplot using precalculated (summary) statistics

前端 未结 3 1013
抹茶落季
抹茶落季 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:28

    Thanks to the comment of @tacaswell I was able to find the required documentation and come up with an example using Matplotlib 1.4.3. However, this example does not automatically scale the figure to the correct size.

    import matplotlib.pyplot as plt
    
    item = {}
    
    item["label"] = 'box' # not required
    item["mean"] = 5 # not required
    item["med"] = 5.5
    item["q1"] = 3.5
    item["q3"] = 7.5
    #item["cilo"] = 5.3 # not required
    #item["cihi"] = 5.7 # not required
    item["whislo"] = 2.0 # required
    item["whishi"] = 8.0 # required
    item["fliers"] = [] # required if showfliers=True
    
    stats = [item]
    
    fig, axes = plt.subplots(1, 1)
    axes.bxp(stats)
    axes.set_title('Default')
    y_axis = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    y_values = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
    plt.yticks(y_axis, y_values)
    

    Relevant links to the documentation:

    • Axes.bxp() function
    • boxplot_stats datastructure
    • other examples using Axes.bxp

提交回复
热议问题