Public
Edited
Jan 1, 2024
Insert cell
Insert cell
{
let width = 600,
height = 200,
X = cm.range(width, -3, 3),
sigma = 0.5,
step = 0.01;

function update(app) {
const curve = bellCurve(0, sigma);

app.append(cm.clear, { fill: "#fff" });

app
.data(X)
.append(cm.line, {
x: (_, i) => i,
y: (d) => curve(d),
stroke: "black",
strokeWidth: 2
})
.transform(cm.mapPosition, {
domainY: [0, 1],
padding: 5,
reverseY: true
});

sigma += step;
if (sigma > 2 || sigma < 0.3) step *= -1;
}

function dispose(app) {
invalidation.then(() => app.dispose());
}

return cm
.app({ width: 600, height: 200 })
.on("update", update)
.call(dispose)
.start()
.node();
}
Insert cell
function bellCurve(mu = 0, sigma = 1) {
const sq2pi = Math.sqrt(cm.TWO_PI);
const sdsq = sigma * sigma;
return (x) => {
const xmsq = -1 * (x - mu) * (x - mu);
return (1 / (sigma * sq2pi)) * Math.pow(Math.E, xmsq / sdsq);
};
}
Insert cell
Insert cell
import { quote } from "@pearmini/charming-shared"
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