Public
Edited
Feb 14, 2024
1 fork
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
// .attr("width", width)
// .attr("height", height)
// .attr("viewBox", [0, 0, width, height])
// .attr("style", "max-width: 100%; height: auto; height: intrinsic;")
.attr("viewBox", [0, 0, width, height])
.attr("id", "clip")



svg.append("path")
.datum(defect_spectrum)
.attr("fill", "#0000fe")
.attr("stroke", "#4682b4")
.attr("stroke-width", 0.5)
.attr("d", area);
svg.append("g")
.call(xAxis);

svg.append("g")
.call(yAxis);
svg.call(d3.axisBottom(x).tickFormat(d3.format(".4")));
return svg.node()
}
Insert cell
defect_spectrum
X*
Y*
Color
Size
Facet X
Facet Y
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Select a data source…
Type SQL, then Shift-Enter. Ctrl-space for more options.

Insert cell
defect_spectrum = FileAttachment("defect_spectrum.csv").csv()

Insert cell
defect_spectrum.ydata

Insert cell
margin = ({top: 20, right: 20, bottom: 30, left: 40})
Insert cell
height = 400 - margin.top - margin.bottom
Insert cell
width = 800 - margin.left - margin.right

Insert cell
x = d3.scaleLinear()
// .domain(d3.extent(defect_spectrum, d => d.xdata))
.domain([0, 6500])
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLog()
.domain([1e0, 1e6])
.range([height - margin.bottom, margin.top])
.base(10)
Insert cell
area = d3.area()

.x(function(d) {
return x(d.xdata);
})
.y0(y(1e0))
.y1(function(d) {
return y(d.ydata+6.5e3);
})
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0))

Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x",3)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(defect_spectrum.ydata))
Insert cell
d3 = require("d3@^5.9")
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