d3.js 3D array interpolation

隐身守侯 提交于 2019-12-05 12:05:02

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/

With some effort you might be able to translate an existing algorithm to JavaScript.

  • Octave is open source and provides a method for scattered data interpolation:

http://www.dm.unibo.it/~achilles/calc/octave.html/Interpolation-on-Scattered-Data.html

The source code of Octave is available at

ftp://ftp.gnu.org/gnu/octave/

The file griddata.m and some referenced files can be found in the folder

octave_{version}\scripts\geometry

  • D3.js seems to provide some voronoi and delaunay functionality that might be helpful:

https://github.com/d3/d3/wiki/Voronoi-Geom

http://bl.ocks.org/mbostock/4341156

  • Python also provides a griddata method:

http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.griddata.html#scipy.interpolate.griddata

Plotly.js is based on D3.js and able to create contour plots for scattered data:

https://jsfiddle.net/vwksaob3/

var data = [ {      
  x: [0, 1, 1, 0],
  y: [0, 0, 1, 1],
  z: [0, 0, 1, 1],
  type: 'contour',  
  colorscale: 'Jet',
  showscale: false,
  autocontour: true  
}];

var layout = {
margin: {
b: 0,
l: 0,
r: 0,
t: 0
},
height: 600,
width: 600,
  title: '',
  xaxis: {
        ticks: '',
      showticklabels: false  

  },
  yaxis: {
       ticks: '',
       showticklabels: false     
  } 
};

Plotly.newPlot('graph', data, layout, {displayModeBar: false});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!