theplot = {
const margin = {top: 20, right: 20, bottom: 10, left: 50};
const svg = d3.select(DOM.svg(width + margin.left + margin.right, height + margin.top + margin.bottom))
const g = svg.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
const x = d3.scaleLinear().domain([0, n-1]).range([margin.left, width - margin.right]).nice();
const y = d3.scaleLinear().domain([-20, 20]).range([height - margin.bottom, margin.top]);
svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x))
.append('text')
.text("time (t)")
.attr("fill", "black")
.style("font-size", "11pt")
.attr('x', (width + margin.left) / 2)
.attr('y', margin.bottom * 3.5);
svg.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.attr("class", "y-axis")
.append('text')
.text("Y_t")
.attr("fill", "black")
.style("font-size", "11pt")
.attr('x', -margin.left / 2)
.attr('y', margin.top);
svg.append("line")
.attr("class", "zeroline")
.style("stroke", "black")
.style("stroke-width", 1)
.attr("x1", x(0))
.attr("x2", width - margin.right)
.attr("y1", y(0))
.attr("y2", y(0));
if(phi < 1) {
svg.append("line")
.attr("class", "meanline")
.style("stroke", "red")
.style("stroke-width", 1)
.attr("x1", x(0))
.attr("x2", width - margin.right)
.attr("y1", y(ymean))
.attr("y2", y(ymean));
}
const line = d3.line()
.x((_, i) => x(i))
.y(d => y(d));
const errorsPath = svg.append("path")
.datum(errors)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("d", line);
const arma11Path = svg.append("path")
.datum(arma11)
.attr("fill", "none")
.attr("stroke", "red")
.attr("stroke-width", 1.5)
.attr("stroke-dasharray", "5,5")
.attr("d", line);
const legend = svg.append("g")
.attr("class", "legend")
.style("font-size", "10pt")
.attr("transform", `translate(${width - 170}, 30)`);
legend.append("line")
.style("stroke", "steelblue")
.attr("x1", 0).attr("y1", 0)
.attr("x2", 15).attr("y2", 0)
.attr("stroke-width", 2);
legend.append("text")
.attr("x", 20).attr("y", 5)
.text("Gaussian innovations");
legend.append("line")
.style("stroke", "red")
.attr("stroke-dasharray", "5,5")
.attr("x1", 0).attr("y1", 20)
.attr("x2", 15).attr("y2", 20)
.attr("stroke-width", 2);
legend.append("text")
.attr("x", 20).attr("y", 25)
.text("ARMA(1,1) process");
legend.append("line")
.style("stroke", "red")
.attr("x1", 0).attr("y1", 40)
.attr("x2", 15).attr("y2", 40)
.attr("stroke-width", 2);
legend.append("text")
.attr("x", 20).attr("y", 45)
.text("stationary mean");
y.domain(newYDomain);
svg.select(".y-axis").transition().duration(2000).call(d3.axisLeft(y));
svg.select(".zeroline").transition().duration(2000).attr("y1", y(0)).attr("y2", y(0));
svg.select(".meanline").transition().duration(2000).attr("y1", y(ymean)).attr("y2", y(ymean));
errorsPath.datum(errors).transition().duration(2000).attr("d", line);
arma11Path.datum(arma11).transition().duration(2000).attr("d", line);
return svg.node();
}