diff --git a/src/examples.jl b/src/examples.jl index 19b167ad..5208b9af 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -480,6 +480,23 @@ PlotExample("Histogram2D (complex values)", end)] ), +PlotExample("Unconnected lines using NaN values", +""" +Non-finite values, including `NaN`, are not plotted. +Instead, lines are separated into segments at these values. +""", + [:(begin + x,y = [1,2,2,1,1], [1,2,1,2,1] + plot( + plot([rand(5); NaN; rand(5); NaN; rand(5)]), + plot([1,Inf,2,3], marker=true), + plot([x; NaN; x.+2], [y; NaN; y.+1], arrow=2), + plot([1, 2+3im, Inf, 4im, 3, -Inf*im, 0, 3+3im], marker=true), + legend=false + ) + end)] +), + ] # Some constants for PlotDocs and PlotReferenceImages diff --git a/src/series.jl b/src/series.jl index bbc2248f..5c0ffeac 100644 --- a/src/series.jl +++ b/src/series.jl @@ -14,7 +14,10 @@ const SeriesData = Union{AVec{<:DataPoint}, Function, Surface, Volume} prepareSeriesData(x) = error("Cannot convert $(typeof(x)) to series data for plotting") prepareSeriesData(::Nothing) = nothing -prepareSeriesData(s::SeriesData) = handlemissings(s) +prepareSeriesData(s::SeriesData) = handleinfinites(handlemissings(s)) + +handleinfinites(s) = s +handleinfinites(s::AbstractArray{<:MaybeNumber}) = [isinf(x) ? NaN : x for x in s] handlemissings(v) = v handlemissings(v::AbstractArray{<:MaybeNumber}) = replace(v, missing => NaN)