Public
Edited
Jan 26, 2021
1 fork
11 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
density = {
let w = Math.min(675, width);
return pointDensity(w, Math.round(w / 1.5))
.xDomain([-3.5, 3.5])
.yDomain([-2.25, 2.25]);
}
Insert cell
color = d3.scaleDivergingLog(
[0.1, 1, 10],
// cacheInterpolator speeds up colorization by returning cached {r, g, b} objects
cacheInterpolator(d3.interpolateRdBu)
)
Insert cell
maxPoints = 1e6
Insert cell
stdev = 0.5
Insert cell
// Smooth the fraction a / b towards x with strength α
smooth = (a, b, x, α) => (a + x * α) / (b + α)
Insert cell
rand = d3.randomNormal(0, stdev) // Sample coordinates from a normal distribution
Insert cell
dataA = allDataA.slice(0, Math.round(numPoints / 2))
Insert cell
dataB = allDataB.slice(0, Math.round(numPoints / 2))
Insert cell
allDataA = generate(Math.ceil(maxPoints / 2), -1)
Insert cell
allDataB = generate(Math.ceil(maxPoints / 2), 1)
Insert cell
generate = (length, sign) =>
Array.from({ length }, () => [rand() - sign * .5 * stdev * offset, rand()])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {
densityPlot,
pointDensity,
cacheInterpolator
} from '@twitter/density-plot@4159'
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more