Skip to content

箱线图:求四分位数错误 #5094

Closed
@bingbig

Description

@bingbig

###求四分位数错误

var data = echarts.dataTool.prepareBoxplotData([
    [5.61,5.28,5.12,5.06,4.96,4.65,3.74,3.28,3.22,2.63,2.58,1.36,1.34,1.29,1.22,1.04,1,0.95,0.94,0.82,0.67,0.52,0.44,0.43,0.43,0.35,0.33,0.29,0.2,0.19,0.17,0.13,0.12,0.1,0.01,0.01],
    [6.61,6.27,5.44,5.37,5.26,5.23,4.62,3.76,2.1,1.83,1.66,1.59,1.44,1.36,1.32,1.25,1.22,1.09,0.76,0.73]
]);

生成的箱线图如下,为何会存在负值,而且最大值和最小值都不对。
image

Version & Environment [版本及环境]

  • ECharts version [^3.4.0]:
  • Browser version [chrome Version 56.0.2924.87 (64-bit)]:
  • OS Version [mac os X 10.11.6 (15G1217)]:

Expected behaviour [期望结果]

ECharts option [ECharts配置项]

option = {
title: [
        {
            text: 'Michelson-Morley Experiment',
            left: 'center',
        },
        {
            text: 'upper: Q3 + 1.5 * IRQ \nlower: Q1 - 1.5 * IRQ',
            borderColor: '#999',
            borderWidth: 1,
            textStyle: {
                fontSize: 14
            },
            left: '10%',
            top: '90%'
        }
    ],
    tooltip: {
        trigger: 'item',
        axisPointer: {
            type: 'shadow'
        }
    },
    grid: {
        left: '10%',
        right: '10%',
        bottom: '15%'
    },
    xAxis: {
        type: 'category',
        data: data.axisData,
        boundaryGap: true,
        nameGap: 30,
        splitArea: {
            show: false
        },
        axisLabel: {
            formatter: 'expr {value}'
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        name: 'km/s minus 299,000',
        splitArea: {
            show: true
        }
    },
    series: [
        {
            name: 'boxplot',
            type: 'boxplot',
            data: data.boxData,
            tooltip: {
                formatter: function (param) {
                    return [
                        'Experiment ' + param.name + ': ',
                        'upper: ' + param.data[4],
                        'Q3: ' + param.data[3],
                        'median: ' + param.data[2],
                        'Q1: ' + param.data[1],
                        'lower: ' + param.data[0]
                    ].join('<br/>')
                }
            }
        },
        {
            name: 'outlier',
            type: 'scatter',
            data: data.outliers
        }
    ]

}

Other comments [其他信息]

Activity

changed the title [-]箱线图:prepareBoxplotData求四分位数存在问题?[/-] [+]箱线图:prepareBoxplotData求四分位数错误[/+] on Feb 17, 2017
changed the title [-]箱线图:prepareBoxplotData求四分位数错误[/-] [+]箱线图:求四分位数错误[/+] on Feb 17, 2017
100pah

100pah commented on Feb 17, 2017

@100pah
Member

prepareBoxplotData 这个工具方法参考了:https://en.wikipedia.org/wiki/Box_plot,其中,
boxplot 的 两个『须』的端点有几个可能的定义,比如,

  • 可以是 Q1 - 1.5 * IQRQ3 + 1.5 * IQR
    prepareBoxplotData 默认情况下,采用这种定义,也就是说,echarts.dataTool.prepareBoxplotData([ ... ]) 可能出现负值。

  • 可以是『最大最小值』
    echarts.dataTool.prepareBoxplotData([ ... ], {boundIQR: 'none'}) 则使用这种定义,不会出现负值。

bingbig

bingbig commented on Feb 17, 2017

@bingbig
Author

@100pah 之后我看了源码默认是这样算的,我还以为源码那边判断写反了呢。没想到箱线图还有多种算法,学习了,谢谢🙏!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pissang@100pah@bingbig

        Issue actions

          箱线图:求四分位数错误 · Issue #5094 · apache/echarts