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

Plot breaks when adding incorrect input #1908

Open
BioTurboNick opened this issue Jan 31, 2019 · 5 comments
Open

Plot breaks when adding incorrect input #1908

BioTurboNick opened this issue Jan 31, 2019 · 5 comments
Labels

Comments

@BioTurboNick
Copy link
Member

BioTurboNick commented Jan 31, 2019

plot()
plot!([1, 2], [3, 5])
plot!([1], [3, 5]) # Generates an error (see below)
plot!([1, 2], [3, 5]) # Should be valid, generates same error

My guess: Plots is not checking input data for compatible format, stores it as a plot series, and then repeatedly tries to read the bad data when rendering the plot.

Stacktrace:

Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: BoundsError: attempt to access 1-element Array{Int64,1} at index [1:2]
Stacktrace:
 [1] throw_boundserror(::Array{Int64,1}, ::Tuple{UnitRange{Int64}}) at .\abstractarray.jl:484
 [2] checkbounds at .\abstractarray.jl:449 [inlined]
 [3] getindex(::Array{Int64,1}, ::UnitRange{Int64}) at .\array.jl:735
 [4] gr_display(::Plots.Subplot{Plots.GRBackend}, ::Measures.Length{:mm,Float64}, ::Measures.Length{:mm,Float64}, ::Array{Float64,1}) at C:\Users\nicho\.julia\packages\Plots\UQI78\src\backends\gr.jl:1015
 [5] gr_display(::Plots.Plot{Plots.GRBackend}, ::String) at C:\Users\nicho\.julia\packages\Plots\UQI78\src\backends\gr.jl:526
 [6] _show(::IOContext{Base64.Base64EncodePipe}, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.GRBackend}) at C:\Users\nicho\.julia\packages\Plots\UQI78\src\backends\gr.jl:1359
 [7] _showjuno at C:\Users\nicho\.julia\packages\Plots\UQI78\src\output.jl:262 [inlined]
 [8] showjuno(::IOContext{Base64.Base64EncodePipe}, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.GRBackend}) at C:\Users\nicho\.julia\packages\Plots\UQI78\src\output.jl:246
 [9] show(::IOContext{Base64.Base64EncodePipe}, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.GRBackend}) at C:\Users\nicho\.julia\packages\Plots\UQI78\src\output.jl:197
 [10] #base64encode#3(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Function, ::Function, ::MIME{Symbol("image/png")}, ::Vararg{Any,N} where N) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Base64\src\encode.jl:208
 [11] #base64encode at .\none:0 [inlined]
 [12] _binstringmime at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Base64\src\Base64.jl:41 [inlined]
 [13] #stringmime#6(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Function, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.GRBackend}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Base64\src\Base64.jl:38
 [14] (::getfield(Base64, Symbol("#kw##stringmime")))(::NamedTuple{(:context,),Tuple{IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}}}, ::typeof(Base64.stringmime), ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.GRBackend}) at .\none:0
 [15] #stringmime#7(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Function, ::String, ::Plots.Plot{Plots.GRBackend}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Base64\src\Base64.jl:39
 [16] #stringmime at .\none:0 [inlined]
 [17] displayinplotpane(::Plots.Plot{Plots.GRBackend}) at C:\Users\nicho\.julia\packages\Atom\UtmXq\src\display\showdisplay.jl:68
 [18] display(::Atom.JunoDisplay, ::Plots.Plot{Plots.GRBackend}) at C:\Users\nicho\.julia\packages\Atom\UtmXq\src\display\showdisplay.jl:102
 [19] display(::Any) at .\multimedia.jl:287
 [20] #invokelatest#1 at .\essentials.jl:742 [inlined]
 [21] invokelatest at .\essentials.jl:741 [inlined]
 [22] print_response(::IO, ::Any, ::Any, ::Bool, ::Bool, ::Any) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\REPL\src\REPL.jl:155
 [23] print_response(::REPL.AbstractREPL, ::Any, ::Any, ::Bool, ::Bool) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\REPL\src\REPL.jl:140
 [24] (::getfield(REPL, Symbol("#do_respond#38")){Bool,getfield(Atom, Symbol("##170#171")),REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\REPL\src\REPL.jl:714
 [25] #invokelatest#1 at .\essentials.jl:742 [inlined]
 [26] invokelatest at .\essentials.jl:741 [inlined]
 [27] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\REPL\src\LineEdit.jl:2273
 [28] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\REPL\src\REPL.jl:1035
 [29] run_repl(::REPL.AbstractREPL, ::Any) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\REPL\src\REPL.jl:192
 [30] (::getfield(Base, Symbol("##734#736")){Bool,Bool,Bool,Bool})(::Module) at .\client.jl:362
 [31] #invokelatest#1 at .\essentials.jl:742 [inlined]
 [32] invokelatest at .\essentials.jl:741 [inlined]
 [33] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at .\client.jl:346
 [34] exec_options(::Base.JLOptions) at .\client.jl:284
 [35] _start() at .\client.jl:436
@aminya
Copy link
Contributor

aminya commented Oct 13, 2019

This error also happens when you have a legend with a couple of labels, and you want to add a couple more. You can't just add a label for the added line.
plot!(...., labels=all_of_the_labels)

all_of_the_labels should contain all of the labels.

@LilithHafner
Copy link
Contributor

LilithHafner commented Jul 13, 2021

Also note that plot only sometimes throws an error when lengths are mismatched:

julia> using Plots
julia> plot([], [3,4,5])  # Works
WARNING: importing deprecated binding Colors.RGB1 into PlotUtils.
WARNING: importing deprecated binding Colors.RGB1 into Plots.
WARNING: importing deprecated binding Colors.RGB4 into PlotUtils.
WARNING: importing deprecated binding Colors.RGB4 into Plots.
julia> plot([1], [3,4,5])  # Works
julia> plot([1, 2], [3,4,5])
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: BoundsError: attempt to access 1-element Vector{Float64} at index [1:2]
Stacktrace:
  [1] throw_boundserror(A::Vector{Float64}, I::Tuple{UnitRange{Int64}})
    @ Base ./abstractarray.jl:651
  [2] checkbounds
    @ ./abstractarray.jl:616 [inlined]
  [3] getindex(A::Vector{Float64}, I::UnitRange{Int64})
    @ Base ./array.jl:807
  [4] gr_draw_segments(series::Plots.Series, x::Vector{Float64}, y::Vector{Float64}, fillrange::Nothing, clims::Tuple{Float64, Float64})
    @ Plots ~/.julia/packages/Plots/iYDwd/src/backends/gr.jl:1722
  [5] gr_add_series(sp::Plots.Subplot{Plots.GRBackend}, series::Plots.Series)
    @ Plots ~/.julia/packages/Plots/iYDwd/src/backends/gr.jl:1637
  [6] gr_display(sp::Plots.Subplot{Plots.GRBackend}, w::Measures.AbsoluteLength, h::Measures.AbsoluteLength, viewport_canvas::Vector{Float64})
    @ Plots ~/.julia/packages/Plots/iYDwd/src/backends/gr.jl:955
  [7] gr_display(plt::Plots.Plot{Plots.GRBackend}, fmt::String)
    @ Plots ~/.julia/packages/Plots/iYDwd/src/backends/gr.jl:646
  [8] _show(io::IOContext{Base64.Base64EncodePipe}, #unused#::MIME{Symbol("image/png")}, plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/iYDwd/src/backends/gr.jl:1893
  [9] _showjuno
    @ ~/.julia/packages/Plots/iYDwd/src/output.jl:273 [inlined]
 [10] showjuno(io::IOContext{Base64.Base64EncodePipe}, m::MIME{Symbol("image/png")}, plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/iYDwd/src/output.jl:257
 [11] show(io::IOContext{Base64.Base64EncodePipe}, m::MIME{Symbol("image/png")}, plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/iYDwd/src/output.jl:212
 [12] base64encode(::Function, ::MIME{Symbol("image/png")}, ::Vararg{Any, N} where N; context::IOContext{IOBuffer})
    @ Base64 /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Base64/src/encode.jl:211
 [13] _binstringmime
    @ /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Base64/src/Base64.jl:46 [inlined]
 [14] stringmime(m::MIME{Symbol("image/png")}, x::Plots.Plot{Plots.GRBackend}; context::IOContext{IOBuffer})
    @ Base64 /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Base64/src/Base64.jl:43
 [15] stringmime(m::String, x::Plots.Plot{Plots.GRBackend}; context::IOContext{IOBuffer})
    @ Base64 /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Base64/src/Base64.jl:44
 [16] displayinplotpane(x::Plots.Plot{Plots.GRBackend})
    @ Atom ~/.julia/packages/Atom/5NgzM/src/display/showdisplay.jl:84
 [17] display(d::Atom.JunoDisplay, x::Plots.Plot{Plots.GRBackend})
    @ Atom ~/.julia/packages/Atom/5NgzM/src/display/showdisplay.jl:118
 [18] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
 [19] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [20] invokelatest
    @ ./essentials.jl:706 [inlined]
 [21] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:247
 [22] (::REPL.var"#40#41"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:231
 [23] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
 [24] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:229
 [25] (::REPL.var"#do_respond#61"{Bool, Bool, Atom.var"#246#247"{Module}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:798
 [26] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [27] invokelatest
    @ ./essentials.jl:706 [inlined]
 [28] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2441
 [29] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1126
 [30] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:411

@t-bltg t-bltg added the bug label Nov 27, 2022
@BioTurboNick
Copy link
Member Author

This issue appears to be fixed - the middle call doesn't generate an error anymore.

@LilithHafner
Copy link
Contributor

I'm still seeing this issue with Plots v1.38.0

@t-bltg t-bltg reopened this Dec 18, 2022
@BioTurboNick
Copy link
Member Author

BioTurboNick commented Dec 18, 2022

What you posted is a different error though, @LilithHafner . It should probably be a different issue. Eh, I guess it's close enough. Nevermind.

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

4 participants