gpt4 book ai didi

d3.js - d3.scale.quantize()和d3.scale.quantile()有什么区别?

转载 作者:行者123 更新时间:2023-12-03 12:29:58 25 4
gpt4 key购买 nike

从文档中,定义为:
量化

..a variant of linear scales with a discrete rather than continuous range. The input domain is still continuous, and divided into uniform segments based on the number of values in (the cardinality of) the output range.


分位数

...map an input domain to a discrete range. Although the input domain is continuous and the scale will accept any reasonable input value, the input domain is specified as a discrete set of values. The number of values in (the cardinality of) the output range determines the number of quantiles that will be computed from the input domain


这些似乎都将连续的输入域映射到一组离散值。有人可以阐明差异吗?

最佳答案

Coloring Maps具有很好的视觉解释。

量化:

分位数:

On the scatter plot, the previously horizontal bars are now vertical as the colors of each place is determined by its rank, not value.



这是D3 v4中的代码段,显示了量化和分位数的不同结果。
const purples = [
'purple1',
'purple2',
'purple3',
'purple4',
'purple5'
]
const dataset = [1, 1, 1, 1, 2, 3, 4, 5] // try [1, 2, 3, 4, 5] as well
const quantize = d3.scaleQuantize()
.domain(d3.extent(dataset)) // pass the min and max of the dataset
.range(purples)
const quantile = d3.scaleQuantile()
.domain(dataset) // pass the entire dataset
.range(purples)
console.log(quantize(3)) // purples[3]
console.log(quantile(3)) // purples[4]

关于d3.js - d3.scale.quantize()和d3.scale.quantile()有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19258996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com