将许多可能的输入值映射到离散色域

编程入门 行业动态 更新时间:2024-10-27 08:29:16
本文介绍了将许多可能的输入值映射到离散色域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法在d3的顺序量表上。我读的方式(和它的工作原理线性尺度,我觉得我应该可以这样进行:

I can't grok the docs on d3's ordinal scales. The way I read it (and the way it works for linear scales, I feel I should be able to proceed like this:

color = d3.scale.ordinal(); color.domain([0, 100]); // Input is any percentage point 0-100 color.range([ // Output is a scale of colors from "bad" to "good" 'red','orange','blue','green' ]);

这不会给我预期的结果:

This doesn't give me the results I expect:

color(0); // "red". Ok, that makes sense color(1); // "blue". Huh? This should be "red" color(100); // "orange". Really? I'm confused. What's the range? color.range(); //["red", "orange", "blue", "green"]. That looks right... color.domain(); // [0,1,100]. Um...

<

It looks like it's treating inputs as discrete categorical values when I want to treat them like numbers.

推荐答案

正确的方法可以用来处理输入数据。将数字范围映射到离散输出是使用 quantize 。这个区别对我来说不清楚,顺序看起来很直观。

The correct approach for mapping a range of numbers to discrete outputs is to use quantize. The difference wasn't clear to me and ordinal seemed intuitive. Figured it out now.

工作解决方案如下:

color = d3.scale.quantize(); color.domain([0, 100]); color.range([ 'red','orange','blue','green' ]); color(0); // "red" color(1); // "red" color(99); // "green"

这些链接有助于解决这个问题:

These links here helpful in figuring this out:

  • roadtolarissa/blog/2015/01/04/coloring-maps-with-d3/
  • roadtolarissa/blog/2015/01/04/coloring-maps-with-d3/
  • What is the difference between d3.scale.quantize() and d3.scale.quantile()?

更多推荐

将许多可能的输入值映射到离散色域

本文发布于:2023-07-16 04:20:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117772.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:色域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!