d3.scale.quantize() 和 d3.scale.quantile() 有什么区别? [英] What is the difference between d3.scale.quantize() and d3.scale.quantile()?

查看:24
本文介绍了d3.scale.quantize() 和 d3.scale.quantile() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档中,定义是:

量化

<块引用>

.. 具有离散而不是连续范围的线性标度的变体.输入域仍然是连续的,并根据输出范围(的基数)中的值的数量划分为均匀的段.

分位数

<块引用>

...将输入域映射到离散范围.尽管输入域是连续的并且比例尺将接受任何合理的输入值,但输入域被指定为一组离散值.输出范围(的基数)中的值数量决定了将从输入域计算的分位数数量

这些似乎都将连续输入域映射到一组离散值.有人能说明区别吗?

解决方案

Coloring Maps视觉解释.

量化:

分位数:

<块引用>

在散点图上,以前的水平条现在是垂直的,因为每个地方的颜色是由它的等级决定的,而不是值.

这是 D3 v4 中的代码片段,显示了量化和分位数的不同结果.

const Purples = ['紫色1','紫色2','紫色3','紫色4','紫色5']const dataset = [1, 1, 1, 1, 2, 3, 4, 5]//也尝试 [1, 2, 3, 4, 5]const 量化 = d3.scaleQuantize().domain(d3.extent(dataset))//传递数据集的最小值和最大值.range(紫色)const 分位数 = d3.scaleQuantile().domain(dataset)//传递整个数据集.range(紫色)console.log(quantize(3))//紫色 [3]console.log(quantile(3))//紫色 [4]

From the docs, the definitions are:

quantize

..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.

quantile

...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

These both seem to map continuous input domains to a set of discrete values. Can anybody illuminate the difference?

解决方案

Coloring Maps has a great visual explanation.

Quantize:

Quantile:

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

Here's a code snippet in D3 v4 that shows different results in quantize and quantile.

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.scale.quantize() 和 d3.scale.quantile() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆