Public
Edited
Jan 3, 2023
Insert cell
Insert cell
Plot.plot({
grid: true,
padding: 0.05,
x: { label: "Knowledge Vector", axis: "top" },
y: { label: "LEED Categories" },
color: { type: "linear", scheme: "PiYG", unknown: "#ddd", legend: true },
height: 640,
marks: [
Plot.cell(data, {
x: "number_in_season",
y: "season",
fill: "imdb_rating"
}),
Plot.text(
data,
colorContrast({
// luminance: 60,
x: "number_in_season",
y: "season",
fill: "imdb_rating",
text: (d) => (d.imdb_rating == null ? "-" : d.imdb_rating.toFixed(1)),
title: "title"
})
)
]
})
Insert cell
colorContrast = ({ luminance = 60, ...options }) =>
Plot.initializer(options, (data, facets, channels, scales) => {
const contrast = (color) =>
d3.hcl(color).l > luminance ? "black" : "white";
return {
channels: {
fill: {
...channels.fill,
scale: undefined,
value:
channels.fill == null // when options.fill is a constant color such as "red"
|| scales.color == null // when the scale isn't yet available (e.g. hexbin below)
? Array.from(data).fill(contrast(options.fill))
: Array.from(channels.fill.value, (value) => contrast(scales.color(value)))
}
}
};
})
Insert cell
data = simpsons.data
Insert cell
Insert cell
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