Published
Edited
May 16, 2021
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
plot = Plot.plot({
width: plotWidth,
y: {percent: true, label: '%'},
marks: [
Plot.rectY(data,
Plot.binX({y: 'proportion'},
{thresholds: numbins, fill: 'steelblue'}) ),
Plot.line(kernel_density, {stroke: 'firebrick', strokeWidth: 2, curve: 'cardinal'})
]
})
Insert cell
Insert cell
Insert cell
kernel_density = {
let x = d3.scaleLinear().domain(d3.extent(data)).range([40, plotWidth - 20])
let thresholds = x.ticks(numbins)
let bandwidth = randoms_fn.find(d=> d.name==random_fn.name).bandwidth
let density = kde(epanechnikov(bandwidth), thresholds, data)
let sum = d3.sum(density, d => d[1])
// normalize so that integral = 1
return density.map(d => [d[0], d[1] / sum])
}
Insert cell
Insert cell
function epanechnikov(bandwidth) {
return x => Math.abs(x / bandwidth) <= 1 ? (0.75/bandwidth) * (1 - (x / bandwidth)**2) : 0;
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more