Published
Edited
Jun 22, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof color_steps = slider({
min: 0,
max: 30,
step: 1,
value: 10,
title: "Cantidad de colores",
description: "Control para la cantidad de colores a visualizar en la paleta."
})
Insert cell
// Ejemplo, se pueden definir colores mediante HEX, nombre, HSL, RGB/RGBA
swatches(["#ff3399", "hotpink", "hsl(330, 100%, 70.5%)", "rgba(128, 0, 128, 0.2)"])
Insert cell
swatches(["#ff5b62", "#ffca4a", "#8cc835", "#1884c3", "#6a4d92"])
Insert cell
rojo = {
return d3.quantize(d3.interpolateRgbBasis(["#000217", "#ff0000", "#feba2b"]), color_steps);
}
Insert cell
swatches(rojo.slice(0, color_steps));
Insert cell
swatches(d3.quantize(d3.interpolateHcl("#eec5b6", "#784735"), color_steps))
Insert cell
swatches(d3.quantize(d3.interpolateHcl("#00035c", "#ccf0f8"), color_steps))
Insert cell
Insert cell
viewof lum_steps = slider({
min: 0,
max: 100,
step: 1,
value: 10,
title: "Luminosidad",
description: "Control para la luminosidad del color."
})
Insert cell
{
//Hue:16, Saturation: 62% a 84%, Luminosity: 82 a 34
var luminosidad = d3.interpolate(`hsl(16, 62%, ${0.82*lum_steps}%)`, `hsl(16, 84%, ${0.34*lum_steps}%)`);
var colors = d3.quantize(luminosidad, color_steps);
return swatches(colors)
}

Insert cell
Insert cell
color_especies = ({ "setosa": "#b00000", "versicolor": "#00b000", "virginica": "#0000b0"})
Insert cell
function procesar_datos(fila) {
delete fila.Sepal_Width
fila.longitud_sepalo = +fila.Sepal_Length
fila.longitud_petalo = +fila.Petal_Length
fila.especie = fila.Species
fila.area = fila.Petal_Length * fila.Petal_Width / 2;
fila.color = color_especies[fila.especie]
delete fila.Sepal_Length
delete fila.Petal_Length
delete fila.Petal_Width
delete fila.Species
return fila;
}
Insert cell
datos_iris = d3.csv("https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/iris.csv",procesar_datos)
Insert cell
Insert cell
ancho = 450
Insert cell
alto = 450
Insert cell
margen = ({arr: 25, der: 25, abj: 50, izq: 50})
Insert cell
x = d3.scaleLinear()
.domain([d3.min(datos_iris, d => d.longitud_sepalo), d3.max(datos_iris, d => d.longitud_sepalo)])
.range([margen.izq, ancho - margen.der]);
Insert cell
eje_x = function (g) { return g.attr("transform", `translate(0,${alto - margen.abj})`)
.call(d3.axisBottom(x))
.append('text')
.attr('class', 'axis-label')
.text("Longitud Sepalo")
.attr('x', margen.izq + (ancho - margen.izq - margen.der) / 2)
.attr('y', 10) // Relative to the x axis.)
}
Insert cell
y = d3.scaleLinear()
.domain([d3.min(datos_iris, d => d.longitud_petalo), d3.max(datos_iris, d => d.longitud_petalo)])
.range([alto - margen.abj, margen.arr]);
Insert cell
eje_y = function (g) { return g.attr("transform", `translate(${margen.izq},0)`)
.call(d3.axisLeft(y))}
Insert cell
Insert cell
d3Legend = require('d3-svg-legend')
Insert cell
Insert cell
max_area = d3.max(datos_iris, d => d.area);
Insert cell
min_area = d3.min(datos_iris, d => d.area)
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
Insert cell
Insert cell
//Leyenda
leyenda= legend({
color: d3.scaleSequential([min_area, max_area], d3.interpolateLab("red","blue")),
title: "Area del Petalo"
})
Insert cell
Insert cell
Insert cell
Insert cell
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