# Coloring Different Areas under a Normal Distribution based on X axis

I am trying to achieve results like those below. I am able to get a normal distribution thatβs somewhat broken up with vertical bars:

``````π=1500
π=300
plot(Normal(π,π), title="Normal Distribution N(\$(π),\$(π))", lw=3, label=["SAT Distribution"])
vline!([1200,1800], label="1 Standard Deviation")
vline!([900, 2100], label="2 Standard Deviations")
vline!([600, 2400], label="3 Standard Deviations")
``````

But Iβd really prefer to be able to color the portion under a graph in different colors based on the x axis. Is this possible?

My closest attempt is the following, but it just cuts off the rest of the graph, rather than showing the whole curve:

``````π=1500
π=300
using Rmath
percentile = signifChop(pnorm(1800,π,π)*100,3)
plot(Normal(π,π), title="Normal Distribution N(\$(π),\$(π)) to \$(percentile) percentile", lw=3, label=["SAT Distribution"], fillrange=0)
xlims!((0,1800))
``````

Hereβs a few examples of what Iβd like to be able to create:

For the first plot,

``````let n = Normal(1500,300), (from,x0,to) = (600,1800,2400)
plot(x->pdf(n,x), from, x0, fillrange=0)
plot!(x->pdf(n,x), from, to, c="black")
plot!([x0,x0], [0, pdf(n,x0)], c="black")
end
``````
1 Like

To add on yha solution, you can obtain something similar to the second plot with:

``````let ΞΌ = 1500,
Ο = 300,
n = Normal(ΞΌ,Ο),
(from,x0,x1,x2,x3,x4,x5,to) = ΞΌ .+ (Ο .* (-5, -3, -2 , -1, 1, 2, 3, 5))
plot(x->pdf(n,x), from, to, fillrange=0, c=:red4, legend=false)
plot!(x->pdf(n,x), x0, x5, fillrange=0, c=:gray80, alpha=0.5)
plot!(x->pdf(n,x), x1, x4, fillrange=0, c=:gray80, alpha=0.5)
plot!(x->pdf(n,x), x2, x3, fillrange=0, c=:gray80, alpha=0.5)
plot!(x->pdf(n,x), from, to, c=:black)
vline!([ΞΌ], line=:dash)
end

``````
1 Like