How does d3.scale.quantile work?

前端 未结 2 1597
名媛妹妹
名媛妹妹 2021-02-04 05:24

What is the meaning of this statement?

quantize = d3.scale.quantile().domain([0, 15]).range(d3.range(9));

I saw that the domain is:

2条回答
  •  悲哀的现实
    2021-02-04 05:56

    I would recommend reading over the quantile scale documentation, especially that on quantize.quantiles()

    But basically, d3 sees that there are 9 values in the output range for this scale, so it creates 9 quantiles based on the 2 value data set: [0, 15].
    This leads to the quantize.quantiles() values that you show in your question: [1.6, 3.3, .. ,13.3] , these represent the bounds of the quantiles - anything less than 1.6 will be mapped to the first element of the output range (in this case zero). Anything less than 3.3 and greater than 1.6 will be mapped to the second element of the output range (one). Hence quantize(2) = one, as expected.

提交回复
热议问题