Commit 8e4deb31 authored by Mike Bostock's avatar Mike Bostock
Browse files

Remove kde example.

Replaced by <http://bl.ocks.org/4341954>.
parent 8728e24e
<!DOCTYPE html>
<meta charset="utf-8">
<title>Kernel Density Estimation</title>
<style>
body {
font: 10px sans-serif;
}
path {
stroke: #000;
stroke-width: 1.5px;
fill: none;
}
rect {
fill: steelblue;
}
</style>
<body>
<script src="../../d3.js"></script>
<script src="../../lib/science/science.js"></script>
<script src="../../lib/science/science.stats.js"></script>
<script>
var width = 800,
height = 400;
var x = d3.scale.linear()
.domain([30, 110])
.range([0, width]);
var y = d3.scale.linear()
.domain([0, .1])
.range([0, height]);
var line = d3.svg.line()
.x(function(d) { return x(d[0]); })
.y(function(d) { return height - y(d[1]); });
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
// Based on http://bl.ocks.org/900762 by John Firebaugh
d3.json("../data/faithful.json", function(error, data) {
var bins = d3.layout.histogram().frequency(false).bins(x.ticks(60))(data),
max = d3.max(bins, function(d) { return d.y; }),
kde = science.stats.kde().sample(data);
var bars = svg.selectAll("g.bar")
.data(bins)
.enter().append("g")
.attr("class", "bar")
.attr("transform", function(d) { return "translate(" + x(d.x) + "," + (height - y(d.y)) + ")"; });
bars.append("rect")
.attr("width", function(d) { return x(d.dx + 30) - 1; })
.attr("height", function(d) { return y(d.y); });
svg.selectAll("path")
.data(d3.values(science.stats.bandwidth))
.enter().append("path")
.attr("d", function(h) { return line(kde.bandwidth(h)(d3.range(30, 110, .1))); });
});
</script>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment