How to plot mean +/- deviation in Plots.jl?

Piggybacking on this question … is there a way to get ribbon (or a similar filled error bounds plotting tool) to work with data containing NaN values?

@thompsonmj, this works with gr() back-end but one may need to add some more NaN to avoid leakage:

using Plots; gr()

xs = collect(LinRange(1,20,50))
ys, σs  = log.(xs), rand(length(xs))
xs[10] = NaN; ys[20] = NaN; σs[30] = NaN;
ix = union(findall(isnan,xs), findall(isnan,ys), findall(isnan,σs))
xs[ix] .= NaN; ys[ix] .= NaN; σs[ix] .= NaN; 
Plots.plot( xs,ys, color=:lightblue, ribbon=σs,label=false)
Plots.plot!(xs,ys, color=:blue, marker=(:circle, 7, 1.),label=false)

Plots_gr_ribbon_with_NaNs

4 Likes

OK, so x and y values just need to have NaN in corresponding indices for the data assigned to the ribbon. Thank you!