How can I shade an area under a curve between two lines?

I am plotting a normal curve and I want shaded some areas in this curve. I want to shaded to values minor than -1.96 e greater than 1.96. I tried some options: fill and fill area but I didn’t get sucess.

x = rand( Normal( 0 , 1 ),1000000)
plot(x,seriestype=:density,label=“x series”)
vline!([-1.96], line=:dash)
vline!([1.96], line=:dash)

Try vspan! or hspan! instead of vline!.


will do that, a screenshot of the appearance is at

1 Like

Thank you!! It works!

Maybe you could share an example of usage? That would help future readers fine-tune their shading options :+1:

1 Like

I change the npdensity(z) of mcreel to work with superior and inferior limits to solve my problem. I want to plot the normal curve to show examples of hypothesis testing.

using KernelDensity, Plots, Distributions

function npdensity(z,inferior,superior)

    n = size(z,2)
    p = zeros(n)
    for i = 1:n
        x = z[:,i]
        y = kde(x)
        q05 = quantile(x,0.05)
        Plots.plot(range(minimum(x), stop=inferior, length=100),z->pdf(y,z), color=:red, fill=(0,0.5,:red), label="-Zc")
        q95 = quantile(x,0.95)
        Plots.plot!(range(inferior, stop=superior, length=100),z->pdf(y,z), color=:green, fill=(0,0.5,:green),label="Região de Aceitação")
        Plots.plot!(range(superior, stop=maximum(x), length=100),z->pdf(y,z), color = :red, fill=(0,0.5,:red),label="Zc")
        m = mean(x)
        Plots.plot!([m,m],[0,pdf(y,m)],color=:blue, label="média")
        m = median(x)
        if i == 1
            p = Plots.plot!([m,m],[0,pdf(y,m)],color=:black, label="mediana")
            p = [p, Plots.plot!([m,m],[0,pdf(y,m)],color=:black, label="mediana")]
    return p

parafusos = rand( Normal( 0 , 1 ),1000000)