Convert infinite values to NaN
This commit is contained in:
parent
978f00bbb9
commit
224858dad5
@ -480,6 +480,23 @@ PlotExample("Histogram2D (complex values)",
|
|||||||
end)]
|
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
|
# Some constants for PlotDocs and PlotReferenceImages
|
||||||
|
|||||||
@ -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(x) = error("Cannot convert $(typeof(x)) to series data for plotting")
|
||||||
prepareSeriesData(::Nothing) = nothing
|
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) = v
|
||||||
handlemissings(v::AbstractArray{<:MaybeNumber}) = replace(v, missing => NaN)
|
handlemissings(v::AbstractArray{<:MaybeNumber}) = replace(v, missing => NaN)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user