Published
Edited
Apr 4, 2022
1 fork
7 stars
Also listed in…
Plot Examples
Plot
Insert cell
Insert cell
data = FileAttachment("trials.json").json()
Insert cell
Plot.plot({
x: {
nice: true,
ticks: 20,
tickFormat: (d) =>
d === Math.floor(d) ? d3.format("~s")(Math.pow(10, d)) : "•",
label: "sample size (log scale) →"
},
marks: [
Plot.rectY(
data,
Plot.binX(
{
y: "count",
title
},
{
x: (d) => Math.log10(d || NaN),
fill: "orange"
}
)
),
Plot.tickY([0])
]
})
Insert cell
Insert cell
d3.range(0.6, 6.2, 0.2).map((tick) => Math.floor(Math.pow(10, tick)))
Insert cell
Insert cell
Plot.plot({
x: {
ticks: 12,
transform: (d) => Math.pow(10, d),
type: "log",
tickFormat: "~s",
label: "sample size (log scale) →"
},
marks: [
Plot.rectY(
data,
Plot.binX(
{ y: "count" },
{
x: (d) => Math.log10(d || NaN)
}
)
)
]
})
Insert cell
// a brave function that takes a sample value and returns the interval that contains it
title = ([d]) => {
const lo = Math.pow(10, Math.floor(Math.log10(d) * 5) / 5);
const hi = Math.pow(10, (1 + Math.floor(Math.log10(d) * 5)) / 5);
return `[${Math.floor(lo)}-${Math.floor(hi - 1)}]`;
}
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