Public
Edited
Oct 24, 2023
1 fork
Importers
12 stars
Also listed in…
d3-scale
Insert cell
Insert cell
histogram1 = d3.bin()
.value(d => d.date)
.thresholds(20)
(data)
Insert cell
Insert cell
Insert cell
function thresholdTime(n) {
return (data, min, max) => {
return d3.scaleUtc().domain([min, max]).ticks(n);
};
}
Insert cell
histogram2 = d3.bin()
.value(d => d.date)
.thresholds(thresholdTime(20))
(data)
Insert cell
Insert cell
Insert cell
function display(bins) {
const format = d3.utcFormat("%Y-%m-%d");
return md`| start | end | timestamp<sup>1</sup> | #events | median value |
|-----|-----|-----|-----|----|
${bins
.slice(0, 8)
.map(
d =>
`| ${format(d.x0)} | ${format(d.x1)} | ${+d.x0} | ${
d.length
} | ${d3.median(d, d => d.value)}`
)
.join("\n")}
| … etc.|

<small><sup>1</sup> in milliseconds relative to [EPOCH](https://en.wikipedia.org/wiki/Epoch_%28computing%29).
`;
}
Insert cell
data = {
const data = [];
// https://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts+dSST.csv
await d3.csvParse(await FileAttachment("temperatures.csv").text(), (d, i, columns) => {
for (let i = 1; i < 13; ++i) {
data.push({
date: new Date(Date.UTC(d.Year, i - 1, 1)),
value: +d[columns[i]]
});
}
});
return data;
}
Insert cell
Insert cell
Plot.rectY(data, Plot.binX({y: "median"}, {x: "date", y: "value", thresholds: 20})).plot()
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