D3 Color Schemes Click any d3-scale-chromatic scheme below to copy it to the clipboard.

viewof n = html`<select> <option value=256>continuous</option>${d3.range(11, 2, -1).map(n => ` <option value=${n}>discrete (${n})</option>`)} </select>`

Sequential (Single-Hue)

Blues = ramp("Blues")

Greens = ramp("Greens")

Greys = ramp("Greys")

Oranges = ramp("Oranges")

Purples = ramp("Purples")

Reds = ramp("Reds")

Sequential (Multi-Hue)

BuGn = ramp("BuGn")

BuPu = ramp("BuPu")

GnBu = ramp("GnBu")

OrRd = ramp("OrRd")

PuBuGn = ramp("PuBuGn")

PuBu = ramp("PuBu")

PuRd = ramp("PuRd")

RdPu = ramp("RdPu")

YlGnBu = ramp("YlGnBu")

YlGn = ramp("YlGn")

YlOrBr = ramp("YlOrBr")

YlOrRd = ramp("YlOrRd")

Viridis = ramp("Viridis")

Inferno = ramp("Inferno")

Magma = ramp("Magma")

Plasma = ramp("Plasma")

Warm = ramp("Warm")

Cool = ramp("Cool")

CubehelixDefault = ramp("CubehelixDefault")

Diverging

BrBG = ramp("BrBG")

PRGn = ramp("PRGn")

PiYG = ramp("PiYG")

PuOr = ramp("PuOr")

RdBu = ramp("RdBu")

RdGy = ramp("RdGy")

RdYlBu = ramp("RdYlBu")

RdYlGn = ramp("RdYlGn")

Spectral = ramp("Spectral")

Cyclical

Rainbow = ramp("Rainbow")

Sinebow = ramp("Sinebow")

Categorical

Category10 = swatches("Category10")

Accent = swatches("Accent")

Dark2 = swatches("Dark2")

Paired = swatches("Paired")

Pastel1 = swatches("Pastel1")

Pastel2 = swatches("Pastel2")

Set1 = swatches("Set1")

Set2 = swatches("Set2")

Set3 = swatches("Set3")

function swatches(name) { const colors = d3[`scheme${name}`]; const n = colors.length; const dark = d3.lab(colors[0]).l < 50;; const canvas = svg`<svg viewBox="0 0 ${n} 1" style="display:block;width:${n * 33}px;height:33px;margin:0 -14px;cursor:pointer;">${colors.map((c, i) => svg`<rect x=${i} width=1 height=1 fill=${c}>`)}`; const label = document.createElement("DIV"); label.textContent = name; label.style.position = "absolute"; label.style.top = "4px"; label.style.color = dark ? `#fff` : `#000`; canvas.onclick = () => { label.textContent = "Copied!"; copy(JSON.stringify(colors)); setTimeout(() => label.textContent = name, 2000); }; return html`${canvas}${label}`; }

function ramp(name) { let canvas; let colors; let dark; if (d3[`scheme${name}`] && d3[`scheme${name}`][n]) { colors = d3[`scheme${name}`][n]; dark = d3.lab(colors[0]).l < 50; } else { const interpolate = d3[`interpolate${name}`]; colors = []; dark = d3.lab(interpolate(0)).l < 50; for (let i = 0; i < n; ++i) { colors.push(d3.rgb(interpolate(i / (n - 1))).hex()); } } if (n < 128) { canvas = svg`<svg viewBox="0 0 ${n} 1" style="display:block;shape-rendering:crispEdges;width:calc(100% + 28px);height:33px;margin:0 -14px;cursor:pointer;" preserveAspectRatio="none">${colors.map((c, i) => svg`<rect x=${i} width=1 height=1 fill=${c}>`)}`; } else { const context = (canvas = DOM.canvas(n, 1)).getContext("2d"); canvas.style.margin = "0 -14px"; canvas.style.width = "calc(100% + 28px)"; canvas.style.height = "33px"; canvas.style.cursor = "pointer"; for (let i = 0; i < n; ++i) { context.fillStyle = colors[i]; context.fillRect(i, 0, 1, 1); } } const label = document.createElement("DIV"); label.textContent = name; label.style.position = "absolute"; label.style.top = "4px"; label.style.color = dark ? `#fff` : `#000`; canvas.onclick = () => { label.textContent = "Copied!"; copy(JSON.stringify(colors)); setTimeout(() => label.textContent = name, 2000); }; return html`${canvas}${label}`; }

function copy(text) { const fakeElem = document.body.appendChild(document.createElement("input")); fakeElem.style.position = "absolute"; fakeElem.style.left = "-9999px"; fakeElem.setAttribute("readonly", ""); fakeElem.value = "" + text; fakeElem.select(); try { return document.execCommand("copy"); } catch (err) { return false; } finally { fakeElem.parentNode.removeChild(fakeElem); } }

d3 = require("d3-array@1", "d3-color@1", "d3-scale-chromatic@1")