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

violin with more series than datapoints per series causes error #121

Closed
baggepinnen opened this issue Dec 22, 2017 · 4 comments
Closed

violin with more series than datapoints per series causes error #121

baggepinnen opened this issue Dec 22, 2017 · 4 comments
Labels

Comments

@baggepinnen
Copy link
Contributor

julia> using StatPlots

julia> violin(randn(10,3)) # Works fine

julia> violin(randn(10,10)) # Works fine

julia> violin(randn(10,11)) 
ERROR: BoundsError: attempt to access 10-element UnitRange{Int64} at index [11]
Stacktrace:
 [1] throw_boundserror(::UnitRange{Int64}, ::Int64) at ./abstractarray.jl:434
 [2] getindex(::UnitRange{Int64}, ::Int64) at ./range.jl:477
 [3] macro expansion at /local/home/fredrikb/.julia/v0.6/StatPlots/src/violin.jl:21 [inlined]
 [4] apply_recipe(::Dict{Symbol,Any}, ::Type{Val{:violin}}, ::UnitRange{Int64}, ::Array{Float64,1}, ::Void) at /local/home/fredrikb/.julia/v0.6/RecipesBase/src/RecipesBase.jl:287
 [5] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}) at /local/home/fredrikb/.julia/v0.6/Plots/src/pipeline.jl:406
 [6] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Float64,2}}) at /local/home/fredrikb/.julia/v0.6/Plots/src/plot.jl:233
 [7] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::Array{Float64,2}) at ./<missing>:0
 [8] #violin#672(::Array{Any,1}, ::Function, ::Array{Float64,2}, ::Vararg{Array{Float64,2},N} where N) at /local/home/fredrikb/.julia/v0.6/RecipesBase/src/RecipesBase.jl:381
 [9] violin(::Array{Float64,2}, ::Vararg{Array{Float64,2},N} where N) at /local/home/fredrikb/.julia/v0.6/RecipesBase/src/RecipesBase.jl:381
@mkborregaard
Copy link
Member

mkborregaard commented Dec 22, 2017

violin(randn(12,11)) works, though. (sorry I hit the wrong button)

@mkborregaard mkborregaard reopened this Dec 22, 2017
@mkborregaard mkborregaard changed the title violin with more than 10 series causes error violin with more series than datapoints per series causes error Dec 22, 2017
@mkborregaard
Copy link
Member

bloxplot(randn(10,11)) also has this behaviour.

@mkborregaard
Copy link
Member

The error is thrown here:
https://github.com/JuliaPlots/StatPlots.jl/blob/master/src/violin.jl#L21

This line should make x the same for all values in the series recipe, but fails because it uses series_plotindex to index into the default x value provided by Plots, which is only as big as the number of datapoitns in the series.
I've tried to replace by

if !(typeof(x) <: UnitRange)
        x = [getindex(x, plotattributes[:series_plotindex])]
    else
        x = plotattributes[:series_plotindex])
    end

which I think should do the right thing in principle, but it's erroring further into the Plots pipeline. I don't have time to check this further right now.

@mkborregaard
Copy link
Member

The bug was introduced in #95

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

No branches or pull requests

2 participants