Public
Edited
Oct 24, 2023
1 fork
Importers
12 stars
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

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