代码之家  ›  专栏  ›  技术社区  ›  AndrewA

matplotlib框和whisker基础统计信息

  •  0
  • AndrewA  · 技术社区  · 7 年前

    我使用matplotlib创建了长方体和胡须图。我的问题是如何确保图表中显示的计算统计数据与我将通过以下内置函数计算的统计数据相匹配。列的平均值()。据我所知,如果发现了异常值,那么75、50、25个四分位数将反映这一点(计算时没有异常值),因此将不匹配包含异常值的统计数据。我的猜测是,如果我做一个1.5 IQR过滤器,然后运行我的统计数据,例如。mean()它们将匹配。有没有办法直接在matplotlib-box-whisker图使用的统计数据处达到峰值?谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   wwii    7 年前

    您可以调用 boxplot 用于计算数据。

    我一直很幸运地在 Matplotlib source 了解它是如何工作的。 boxplot 使用函数 matplotlib.cbook.boxplot_stats 进行计算。您可以自己调用此函数并检查返回的数据:

    from matplotlib import cbook
    print(help(cbook.boxplot_stats))
    data = cbook.boxplot_stats(values)
    

    boxplot_stats 文档字符串:

    Returns
    -------
    bxpstats : list of dict
        A list of dictionaries containing the results for each column
        of data. Keys of each dictionary are the following:
    
        ========   ===================================
        Key        Value Description
        ========   ===================================
        label      tick label for the boxplot
        mean       arithemetic mean value
        med        50th percentile
        q1         first quartile (25th percentile)
        q3         third quartile (75th percentile)
        cilo       lower notch around the median
        cihi       upper notch around the median
        whislo     end of the lower whisker
        whishi     end of the upper whisker
        fliers     outliers
        ========   ===================================
    

    源链接用于当前 主人 在这个日期。当前Matplotlib版本为2.2.2