pdf_height2 = 1 / (b_unif - a_unif)
uniform_pdf_data2 = [
{x: a_unif - 5, y: 0},
{x: a_unif, y: 0},
{x: a_unif, y: pdf_height2},
{x: b_unif, y: pdf_height2},
{x: b_unif, y: 0},
{x: b_unif + 5, y: 0}
]
// Create shaded area data
shaded_area2 = d3.range(a_unif, b_unif + 0.01, (b_unif - a_unif) / 100).map(x => ({
x: x,
y: pdf_height2
}))
// Markers for mean and standard deviations
markers2 = [
{x: mean_unif, y: pdf_height2 / 2, label: "ฮผ", color: "red"},
{x: mean_unif - sd_unif, y: pdf_height2 * 0.7, label: "ฮผ - ฯ", color: "orange"},
{x: mean_unif + sd_unif, y: pdf_height2 * 0.7, label: "ฮผ + ฯ", color: "orange"}
]
Plot.plot({
width: 800,
height: 450,
marginLeft: 60,
x: {
label: "Y",
grid: true
},
y: {
label: "Density f(y)",
domain: [0, pdf_height2 * 1.3]
},
marks: [
Plot.areaY(shaded_area2, {x: "x", y: "y", fill: "steelblue", opacity: 0.3}),
Plot.line(uniform_pdf_data2, {x: "x", y: "y", stroke: "steelblue", strokeWidth: 3}),
Plot.ruleX([mean_unif], {stroke: "red", strokeWidth: 2, strokeDasharray: "5,3"}),
Plot.ruleX([mean_unif - sd_unif, mean_unif + sd_unif], {stroke: "orange", strokeWidth: 1.5, strokeDasharray: "3,3"}),
Plot.dot(markers2, {x: "x", y: "y", fill: "color", r: 6, stroke: "white", strokeWidth: 2}),
Plot.text(markers2, {x: "x", y: "y", text: "label", dy: -12, fontSize: 14, fontWeight: "bold"}),
Plot.ruleY([0])
],
caption: html`<span style="color: red;">โโ</span> Mean | <span style="color: orange;">โ โ</span> ยฑ 1 Standard Deviation`
})