Intervals.jl
Intervals.jl copied to clipboard
Plotting intervals throws several warnings
In the present version of plots, I am hitting this warning which is causing a lot of spam around plots.
At some point, it looks like Plots changed from using NaN segments to using a vector of coordinates [from v1.11] This breaks the assumption here. Under the hood, I believe this was converting the y series into something like [1.0, 1.0, NaN, 1.0, 1.0, NaN, 1.0, 1.0, NaN]...etc. Now however, we want to do [[1.0, 1.0], [1.0, 1.0], [1.0, 1.0]]
This looks like it will fix it [tested locally, will add into an MR at some point]
@recipe function f(xs::AbstractVector{<:AbstractInterval{T,L,R}}, ys) where {T, L <: Bounded, R <: Bounded}
new_xs = Vector{T}[]
new_ys = Vector{Any}[]
markers = Symbol[]
for (x, y) in zip(xs, ys)
# To cause line to not be connected, need to divide individually separated segments into separate vectors
append!(new_xs, [[first(x), last(x)]])
append!(new_ys, [[y, y]])
end
append!(markers, interval_markers(first(xs)))
# Work around GR bug that shows :none as a marker
# TODO: remove once https://github.com/jheinen/GR.jl/issues/295 is fixed
markeralpha := [x == :none ? 0 : 1 for x in markers]
markershape := markers
seriestype := :path # always a path, even in a scatter plot
new_xs, new_ys
end
Can make this into an MR, but this would break older versions of Plots. Can keep both. Looks like behaviour changes slightly too, as now it iterates through the colour map (each line is a different colour).
Related: https://github.com/invenia/Intervals.jl/issues/134
I've came across this issue too, and wonder why a vector of intervals is plotted as a single path. Currently the plotting of Intervals is also broken for vectors of Intervals where the bounds are mixed (e.g. [Interval{Open,Closed}(1,2),Interval{Closed,Closed}(2,3)] is excluded from the signature. For this to work the where clause needs to be moved.
I'm running into this too. Wondering to what extent it would make sense to do something like this, i.e. define the recipe for a single interval & y value?
Then composition over multiple intervals can be achieved with multiple calls to plot!.
@recipe function f(x::AbstractInterval{T,L,R}, y::Real) where {T,L<:Bounded,R<:Bounded}
markers = interval_markers(x)
# TODO: remove once https://github.com/jheinen/GR.jl/issues/295 is fixed
markeralpha := [x == :none ? 0 : 1 for x in markers]
markershape := markers
seriestype := :path # always a path, even in a scatter plot
return [first(x), last(x)], [y, y]
end