Public
Edited
Jan 9, 2023
1 fork
3 stars
Also listed in…
Fil’s plots
Algorithms
Insert cell
Insert cell
walkSteps = (x, y = 0) => {
let d,
t = 0;
d = Math.hypot(x, y);
while (d > 1) {
t++;
const angle = Math.random() * 2 * Math.PI;
x += d * Math.cos(angle);
y += d * Math.sin(angle);
d = Math.hypot(x, y);
}
return t;
}
Insert cell
walkSteps(100)
Insert cell
Insert cell
Plot.plot({
marks: [Plot.dot(d3.range(400), { x: (d) => d, y: (d) => walkSteps(d) })],
y: { type: "log" }
})
Insert cell
Insert cell
f = (angle) => Math.hypot(Math.sin(angle), 1 + Math.cos(angle))
Insert cell
factor = d3
.range(0, Math.PI, 0.04)
.map(f)
Insert cell
Insert cell
Insert cell
Plot.tickX(factor, { stroke: (d) => (d < 1 ? "blue" : "red") }).plot({
x: { transform: Math.log }
})
Insert cell
Insert cell
{
const random = d3.randomLcg(50);
const stop = (V) => {
let stopped = false;
return V.map((d) =>
stopped || d < -Math.log(100) ? ((stopped = true), -Math.log(100)) : d
);
};

return Plot.plot({
y: {
type: "log",
transform: (d) => Math.exp(d) * 100,
domain: [1, Math.exp(33)],
label: "↑ radius",
grid: true
},
marks: [
Plot.lineY(
Array.from({ length: 10000 }, () =>
Math.log(f(random() * 2 * Math.PI))
),
Plot.mapY(
stop,
Plot.mapY("cumsum", {
y: (d) => d,
strokeWidth: 0.75,
x: (d, i) => i % 1000,
stroke: (d, i) => (i / 1000) | 0
})
)
),
Plot.tickY([0, -Math.log(100)])
]
});
}
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