Public
Edited
Oct 26, 2021
Fork of Color Ramp
Importers
6 stars
Insert cell
Insert cell
function ramp(color, n = 256) {
const canvas = DOM.canvas(n, 1);
const context = canvas.getContext("2d");
canvas.style.margin = "0 -14px";
canvas.style.width = "calc(100% + 28px)";
canvas.style.height = "40px";
canvas.style.imageRendering = "pixelated";
for (let i = 0; i < n; ++i) {
context.fillStyle = color(i / (n - 1));
context.fillRect(i, 0, 1, 1);
}
return canvas;
}
Insert cell
Insert cell
disc((r,t) => `hsl(${t},${r}%,50%)`) // The dreaded angry rainbow!
Insert cell
Insert cell
ramp(d3.interpolateRainbow) // A better cylical color scheme.
Insert cell
ramp(d3.interpolateViridis) // A nice sequential color scheme.
Insert cell
ramp(d3.interpolateViridis, 12) // With a discrete number of steps.
Insert cell
ramp(d3.interpolateRgb("red", "blue")) // Also works nicely with D3 interpolators.
Insert cell
ramp(d3.interpolateHclLong("red", "blue"))
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