Public
Edited
Jan 16, 2023
Fork of Simple D3
Insert cell
Insert cell
xScale = d3.scaleLinear()
.domain([-4, 4])
.range([0, innerWidth])
Insert cell
yScale = d3.scaleLinear()
.domain([-2, 14])
.range([innerHeight, 0])
Insert cell
xAxisQuadratic = d3.axisBottom(xScale)
.tickSize(innerHeight + 10);
Insert cell
yAxisQuadratic = d3.axisLeft(yScale)
.tickSize(innerWidth + 10);
Insert cell
dataQuadratic = [{x: -3, y: 7.5}, {x: -2, y: 3}, {x: -1, y: 0.5}, {x: 0, y: 1}, {x: 1, y: 3}, {x: 2, y: 6}, {x: 3, y: 14}]
Insert cell
Insert cell
quadraticRegression = d3.regressionQuad()
.x(d => d.x)
.y(d => d.y)
.domain([-4, 4]);
Insert cell
lineGenerator = d3.line()
.x(d => xScale(d[0]))
.y(d => yScale(d[1]));
Insert cell
Plot.plot({
width: 640,
marks: [
Plot.line(
build_samples((x) => Math.exp(-x * x), -3, 1),
{
strokeWidth: 3,
stroke: "steelblue"
}
),
Plot.ruleX([0]),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
import {margin} from "@harrystevens/introducing-d3-regression"
Insert cell
base = Math.min(width, 400);
Insert cell
import {innerWidth} from "@harrystevens/introducing-d3-regression"
Insert cell
import {innerHeight} from "@harrystevens/introducing-d3-regression"
Insert cell
d3 = require("d3-array@3", "d3-axis@3", "d3-regression@1", "d3-scale@4", "d3-shape@3", "d3-selection@3")
Insert cell
import {build_samples} from "@mcmcclur/adaptive-plotter"
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