【发布时间】:2017-03-31 14:12:59
【问题描述】:
请看Hexbin和散点图:http://imgur.com/a/2oR68
为什么在 Hexbinplot 中,点不相互接触,而在散点图中却清楚地接触到接近的点?
我预计我的 hexbin 情节会像这样出现:https://bl.ocks.org/mbostock/4248145 但它没有。
我正在使用 d3.hexbin 插件。
除了一点点缩放之外,从 Hexbin 图到散点图(我正在处理相同的数据集)的唯一代码是:
对于Hexbin:
var color = d3.scale.linear()
.range(["white", "steelblue"])
.interpolate(d3.interpolateLab);
var hexbin = d3.hexbin()
.extent([[0,0],[size - padding , padding]])
.radius();
hexbin.x(function(d,i){return x(subdata[0][i]);})
hexbin.y(function(d,i){return y(subdata[0][i]);})
svg.append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("class", "mesh")
.attr("width", w)
.attr("height", size);
svg.append("g")
.attr("clip-path", "url(#clip)")
.selectAll(".hexagon")
.data(hexbin(datum))
.enter()
.append("path")
.attr("class", "hexagon")
.attr("d", hexbin.hexagon())
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.style("fill", function(d) { return color(d.length); });
散点图:
svg.selectAll("circle")
.data(datum)
.enter()
.append("circle")
.style("fill", "steelblue")
.attr("cx", function (d, i) {
return x(subdata[0][i]);
})
.attr("cy", function (d,i) {
return y(subdata[0][i]);
})
.attr("r", 3)
我哪里做错了?
Edit1:在 Hexbin 下包含部分代码
【问题讨论】:
标签: d3.js