What is the difference between d3.scale.quantize() and d3.scale.quantile()?

前端 未结 4 1908
北恋
北恋 2020-12-14 09:12

From the docs, the definitions are:

quantize

..a variant of linear scales with a discrete rather than continuous range. The input domain is sti

4条回答
  •  轮回少年
    2020-12-14 09:46

    In general terms, the difference is similar to the difference between the mean and median.

    The difference is only really apparent when the number of values in the input domain is larger than the number of values in the output domain. Best illustrated by an example.

    For the quantize scale, the input range is divided into uniform segments depending on the output range. That is, the number of values in the domain doesn't really matter. Hence it returns 1 for 0.2, as 0.2 is closer to 1 than 100.

    The quantile scale is based on the quantiles of the input domain and as such affected by the number of values in there. The number of values in the output domain only determines how many quantiles are computed. By their very nature, the quantiles reflect the actual list of values rather than just the range. Thus, an input of 0.2 returns 100 as the corresponding quantile is closer to 100.

提交回复
热议问题