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

Cannot mix DateTime and NaNs to get unconnected line segments #1465

Open
cstjean opened this issue Mar 30, 2018 · 2 comments
Open

Cannot mix DateTime and NaNs to get unconnected line segments #1465

cstjean opened this issue Mar 30, 2018 · 2 comments
Labels
bug enhancement improving existing functionality

Comments

@cstjean
Copy link

cstjean commented Mar 30, 2018

As shown in the docs, it's possible to draw unconnected segments in a single call by adding NaNs for segment breaks. Unfortunately, this fails with DateTime axes.

function rectangle_from_coords(xb,yb,xt,yt)
    Any[
        xb yb
        xt yb
        xt yt
        xb yt
        xb yb
        NaN NaN
    ]
end

d(day) = DateTime(2017, 1, day)
some_rects=[
    rectangle_from_coords(d(1) ,d(1) ,d(5) ,d(5) )
    rectangle_from_coords(d(10),d(10),d(15),d(15))
    ]
plot(some_rects[:,1], some_rects[:,2],label="some group")

gives

MethodError: no method matching value(::Float64)
Closest candidates are:
  value(::Base.Dates.Time) at dates/accessors.jl:46
  value(::Base.Dates.Period) at dates/periods.jl:4
  value(::Base.Dates.TimeType) at dates/accessors.jl:45

Stacktrace:
 [1] collect_to!(::Array{Int64,1}, ::Base.Generator{Array{Any,1},Plots.##294#295}, ::Int64, ::Int64) at ./array.jl:508
 [2] _collect(::Array{Any,1}, ::Base.Generator{Array{Any,1},Plots.##294#295}, ::Base.EltypeUnknown, ::Base.HasShape) at ./array.jl:489
 [3] map(::Function, ::Array{Any,1}) at ./abstractarray.jl:1868
 [4] _apply_type_recipe(::Dict{Symbol,Any}, ::Array{Any,1}) at /home/cedric/.julia/v0.6/Plots/src/series.jl:193
 [5] macro expansion at /home/cedric/.julia/v0.6/Plots/src/series.jl:235 [inlined]
 [6] apply_recipe(::Dict{Symbol,Any}, ::Array{Any,1}, ::Array{Any,1}) at /home/cedric/.julia/v0.6/RecipesBase/src/RecipesBase.jl:287
 [7] _process_userrecipes(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Any,1},Array{Any,1}}) at /home/cedric/.julia/v0.6/Plots/src/pipeline.jl:81
 [8] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Any,1},Array{Any,1}}) at /home/cedric/.julia/v0.6/Plots/src/plot.jl:179
 [9] #plot#192(::Array{Any,1}, ::Function, ::Array{Any,1}, ::Vararg{Array{Any,1},N} where N) at /home/cedric/.julia/v0.6/Plots/src/plot.jl:58
 [10] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::Array{Any,1}, ::Array{Any,1}, ::Vararg{Array{Any,1},N} where N) at ./<missing>:0
 [11] include_string(::String, ::String) at ./loading.jl:522

Similary for strings:

> plot([1,2,3, 3], ["A", "A", "B", NaN])
No user recipe defined for String

Stacktrace:
 [1] convertToAnyVector(::String, ::Dict{Symbol,Any}) at /home/cedric/.julia/v0.6/Plots/src/series.jl:14
 [2] copy!(::Array{Any,1}, ::Base.Generator{Array{Any,1},Plots.##203#205{Dict{Symbol,Any}}}) at ./abstractarray.jl:573
 [3] convertToAnyVector(::Array{Any,1}, ::Dict{Symbol,Any}) at /home/cedric/.julia/v0.6/Plots/src/series.jl:58
 [4] macro expansion at /home/cedric/.julia/v0.6/Plots/src/series.jl:132 [inlined]
 [5] apply_recipe(::Dict{Symbol,Any}, ::Type{Plots.SliceIt}, ::Array{Int64,1}, ::Array{Any,1}, ::Void) at /home/cedric/.julia/v0.6/RecipesBase/src/RecipesBase.jl:287
 [6] _process_userrecipes(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Int64,1},Array{Any,1}}) at /home/cedric/.julia/v0.6/Plots/src/pipeline.jl:81
 [7] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Int64,1},Array{Any,1}}) at /home/cedric/.julia/v0.6/Plots/src/plot.jl:179
@cstjean
Copy link
Author

cstjean commented May 15, 2018

Work-around by passing a vector of alpha values: plot([1,2,3,4], ["A", "A", "B", "B"], alpha=[1.0, 1, 0, 0])

@mkborregaard
Copy link
Member

Maybe a longer term approach could be to allow passing Missing that would then be reinterpreted as NaN when the Dates are converted to Floats by the DateFormatter?

@t-bltg t-bltg added bug enhancement improving existing functionality labels Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement improving existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants