Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting intervals throws several warnings #159

Open
AlexRobson opened this issue Mar 25, 2021 · 2 comments
Open

Plotting intervals throws several warnings #159

AlexRobson opened this issue Mar 25, 2021 · 2 comments

Comments

@AlexRobson
Copy link
Member

AlexRobson commented Mar 25, 2021

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: #134

@AlexRobson AlexRobson changed the title Plotting CIs throws several warnings Plotting intervals throws several warnings Apr 27, 2021
@laborg
Copy link

laborg commented Apr 29, 2021

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.

@tpgillam
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants