Sunspots
Astronomy
Contour Chart
Code
= {
chart const margin = { top: 20, right: 10, bottom: 20, left: 60 };
const width = fullWidth - margin.left - margin.right,
= fullHeight - margin.top - margin.bottom;
height
const window = d3.create("svg")
.attr("width", "100%")
.attr("height", "100%")
.attr("viewBox", `0 0 ${fullWidth} ${fullHeight}`)
.attr("preserveAspectRatio", "xMidYMid meet");
const svg = window.append("g")
.attr("class", "sunspots")
.attr("transform", `translate(${margin.left},${margin.top})`);
const x = d3.scaleLinear()
.domain([1917, 1986])
.rangeRound([0, width]);
const y = d3.scaleLinear()
.domain([-40, 40])
.rangeRound([height, 0]);
const xAxis = d3.axisBottom(x)
.tickValues(d3.range(1910, 1990, 10))
.tickFormat(d3.format("d"));
const yAxis = d3.axisLeft(y);
.append("g")
svg.attr("class", "grid")
.selectAll("path")
.data(d3.range(-30, 40, 10))
.join("path")
.attr("d", d => `M0,${y(d)}H${width}`)
.style("stroke", "lightgrey")
.style("stroke-opacity", 0.7)
.style("shape-rendering", "crispEdges");
.append("g")
svg.attr("class", "contours");
.append("g")
svg.attr("class", "axis axis-x")
.attr("transform", `translate(0,${height})`)
.call(xAxis);
.append("g")
svg.attr("class", "axis axis-y")
.call(yAxis);
.append("text")
svg.attr("alignment-baseline", "hanging")
.attr("dx", 10)
.text("Latitude of sunspot group (deg.)");
const density = d3.contourDensity()
.x(d => x(d.year))
.y(d => y(d.lat))
.size([width, height])
.cellSize(2)
.thresholds(10)
.bandwidth(6)
;
(spots)
const color = d3.scaleSequential(d3.interpolateYlOrBr)
.domain(d3.extent(density, d => d.value));
.select(".contours").selectAll("path")
svg.data(density)
.join("path")
.attr("fill", d => color(d.value))
.attr("d", d3.geoPath());
return window.node();
}
This butterfly diagram shows the latitude distribution of sunspot groups over several past solar cycles.