Can I generate a boxplot without a dataset and only having the relevant values (median, quartiles, etc) in matplotlib?

后端 未结 1 1618
再見小時候
再見小時候 2020-12-18 11:53

I have calculated medians, lower/upper quartiles, minimum and maximum values as part of a separate application of mine and written those values to a file and I would like to

相关标签:
1条回答
  • 2020-12-18 12:36

    There's a baked-in function in matplotlib--bxp--that let's you specify the calculated statistics rather than the raw data to calculate from, avoiding the need to create your own function.

    You'll need to call it as a method from your Axes object rather than from plt:

    import matplotlib.pyplot as plt
    
    stats = [
        {'med': 5, 'q1': 2, 'q3': 6, 'whislo': 1, 'whishi': 8},
        {'med': 4, 'q1': 2, 'q3': 6, 'whislo': 1, 'whishi': 8}
    ]
    
    _, ax = plt.subplots();
    ax.bxp(stats, showfliers=False);
    

    Importantly, your input needs to be a list of dictionaries, corresponding to a list of boxes (even if just 1) to draw.

    0 讨论(0)
提交回复
热议问题