d3.js三维数组插值 [英] d3.js 3D array interpolation

查看:515
本文介绍了d3.js三维数组插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码在这里:


Code is here: http://jsfiddle.net/S48QX/.

I want to draw a image based on a 3D data set, for example:

var data = [
    {x:1.428, y:0.500, energy:0.458},
    {x:1.428, y:1.191, energy:0.616},
    {x:1.428, y:1.882, energy:0.795},
    {x:1.428, y:2.573, energy:0.642},
    {x:1.428, y:3.264, energy:0.536},
    {x:1.428, y:3.955, energy:0.498},
    {x:1.428, y:4.646, energy:0.494},
    {x:1.428, y:5.337, energy:0.517},
     ...

}

It's like scattered plot, but I need every pixel to be set, not just a bunch of color dots on the image. So, my question is how can I interpolate scattered dots with d3.js.

The generated image here is the best I can do so far, but is it possible to make it more smooth and beautiful?

I am seeking a way to generate a HEATMAP only based on partial/scattered data. I hope there is a way in d3.js that can interpolate the missing part.

(1,5) ?   ?   ?  (5,5)
  ?   ?   ?   ?    ?
  ?   ?   ?   ?    ?
(1,2) ?   ?   ?  (5,2)

解决方案

I have one solution using svg filters. Be careful as this may not be what you want since the mathematical interpretation of this interpolation would be more 'blur'. I mostly did it as an exercise on svg filters. However 2d interpolation end up with similar results: see cubic interpolation for example (http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html in python)

I used circles (you could try with rectangles) slightly overlapping and semi transparent and applied to gaussian blur on them, resulting in a 'heatmap' looking thing.

var filter = svg.append("defs").append('filter')
    .attr('id', 'blur')
    .append("feGaussianBlur")
    .attr("stdDeviation", 8);

then using .style('fill-opacity', 0.5).attr("filter", "url(#blur)") on the circles

See the fork http://jsfiddle.net/eqt1mkov/

这篇关于d3.js三维数组插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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