Public
Edited
May 5, 2022
3 forks
15 stars
Insert cell
Insert cell
Insert cell
Insert cell
{
console.time("plot");
// Create and configure a plotter with our density estimator and a color scale
let plot = densityPlot(density)
.size([500, 500])
.background("#fff")
// Customize the color scale to linearly map bin counts to an blue color scale.
.color((buf) =>
d3.scaleSequential(
d3.extent(buf),
// cacheInterpolator speeds up colorization by returning cached {r, g, b, opacity} objects
cacheInterpolator(d3.interpolateBlues)
)
);
let ret = plot(xs);
console.timeEnd("plot");
return ret;
}
Insert cell
Insert cell
// Create and configure a density estimator for our data
density = pointDensity(nBins, nBins)
.x(d => d)
.y((d, i) => ys[i])
// Specify the x and y domains that we'd like to plot
.xDomain([-2.5, 2.5])
.yDomain([-2.5, 2.5])
Insert cell
xs = X.subarray(0, numPoints)
Insert cell
ys = Y.subarray(0, numPoints)
Insert cell
X = Float64Array.from({ length: maxPoints }, rand)
Insert cell
Y = Float64Array.from({ length: maxPoints }, rand)
Insert cell
maxPoints = 1e6
Insert cell
rand = d3.randomNormal(0, 0.75) // Sample coordinates from a normal distribution
Insert cell
d3 = require('d3@6')
Insert cell
comma = d3.format(',')
Insert cell
import { slider } from '@jashkenas/inputs'
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