JuliaPlots / StatsPlots.jl

Statistical plotting recipes for Plots.jl
Other
436 stars 88 forks source link

BoundsError with `errorlines(x, errorstyle=:plume)` #517

Closed this-josh closed 1 year ago

this-josh commented 1 year ago

The plume option only seems to work when appended to an existing plot. This works

julia> using StatsPlots
julia> x = 1:10
julia> y = fill(NaN, 10, 100, 3)
julia> for i = axes(y,3)
           y[:,:,i] = collect(1:2:20) .+ rand(10,100).*5 .* collect(1:2:20) .+ rand()*100
       end
julia> errorline(1:10, y[:,:,1], errorstyle=:ribbon, label="Ribbon")
julia> errorline!(1:10, y[:,:,3], errorstyle=:plume, label="Plume")

However, just plotting plume gives

julia> errorline(1:10, y[:,:,3], errorstyle=:plume, label="Plume")
ERROR: BoundsError: attempt to access 0-element Vector{Plots.Subplot} at index [1]
Stacktrace:
  [1] getindex
    @ ./array.jl:924 [inlined]
  [2] getindex(plt::Plots.Plot{Plots.GRBackend}, i::Int64)
    @ Plots ~/.julia/packages/Plots/yJrrq/src/types.jl:143
  [3] macro expansion
    @ ~/.julia/packages/StatsPlots/faFN5/src/errorline.jl:217 [inlined]
  [4] macro expansion
    @ ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:326 [inlined]
  [5] macro expansion
    @ ~/.julia/packages/StatsPlots/faFN5/src/errorline.jl:211 [inlined]
  [6] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, e::StatsPlots.ErrorLine)
    @ StatsPlots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:289
  [7] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/user_recipe.jl:36
  [8] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/RecipesPipeline.jl:70
  [9] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/yJrrq/src/plot.jl:216
 [10] #plot#149
    @ ~/.julia/packages/Plots/yJrrq/src/plot.jl:91 [inlined]
 [11] errorline(::UnitRange{Int64}, ::Vararg{Any}; kw::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:errorstyle, :label), Tuple{Symbol, String}}})
    @ StatsPlots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:364
 [12] top-level scope
    @ REPL[42]:1

This error doesn't apply to the ribbon and stick methods.

BeastyBlacksmith commented 1 year ago

CC: @CMGreenspon

CMGreenspon commented 1 year ago

On it. I guess I always ran ribbon first so the plot series already existed. Should be an easy fix.

CMGreenspon commented 1 year ago

Have submitted a pull request. If someone could test it that would be ideal.