Public
Edited
May 5, 2022
3 forks
14 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

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