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

Improve Error Messages in the Confusing DivideError when plotting empty data with GR backend #5002

Open
singularitti opened this issue Oct 15, 2024 · 0 comments

Comments

@singularitti
Copy link
Contributor

I encountered an issue when running a plot with empty y-data using the following code:

using Plots

plot([1], [])

This results in the following stack trace:

Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: DivideError: integer division error
Stacktrace:
  [1] div
    @ ./int.jl:295 [inlined]
  [2] div
    @ ./div.jl:310 [inlined]
  [3] div
    @ ./div.jl:355 [inlined]
  [4] fld
    @ ./div.jl:321 [inlined]
  [5] mod
    @ ./int.jl:287 [inlined]
  [6] mod1
    @ ./operators.jl:839 [inlined]
  [7] mod
    @ ./range.jl:1495 [inlined]
  [8] _cycle(v::Vector{Float64}, idx::Int64)
    @ Plots ~/.julia/packages/Plots/kLeqV/src/utils.jl:196
  [9] _guess_best_legend_position(xl::Tuple{…}, yl::Tuple{…}, plt::Plots.Subplot{…}, weight::Int64)
    @ Plots ~/.julia/packages/Plots/kLeqV/src/utils.jl:1216
 [10] _guess_best_legend_position(xl::Tuple{…}, yl::Tuple{…}, plt::Plots.Subplot{…})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/utils.jl:1200
 [11] _guess_best_legend_position(lp::Symbol, plt::Plots.Subplot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/utils.jl:1240
 [12] gr_legend_pos(sp::Plots.Subplot{…}, leg::@NamedTuple{}, vp::Plots.GRViewport{…})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:1145
 [13] gr_add_legend(sp::Plots.Subplot{…}, leg::@NamedTuple{}, viewport_area::Plots.GRViewport{…})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:1008
 [14] gr_display(sp::Plots.Subplot{…}, w::Measures.AbsoluteLength, h::Measures.AbsoluteLength, vp_canvas::Plots.GRViewport{…})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:972
 [15] (::Plots.var"#508#509"{Int64, Int64, Plots.GRViewport{Float64}})(sp::Plots.Subplot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:688
 [16] foreach(f::Plots.var"#508#509"{Int64, Int64, Plots.GRViewport{Float64}}, itr::Vector{Plots.Subplot})
    @ Base ./abstractarray.jl:3187
 [17] gr_display(plt::Plots.Plot{Plots.GRBackend}, dpi_factor::Int64)
    @ Plots ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:688
 [18] gr_display
    @ ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:658 [inlined]
 [19] #564
    @ ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:2114 [inlined]
 [20] withenv(::Plots.var"#564#566"{Plots.Plot{Plots.GRBackend}}, ::Pair{String, String}, ::Vararg{Pair{String}})
    @ Base ./env.jl:265
 [21] _display(plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/backends/gr.jl:2113
 [22] display(::Plots.PlotsDisplay, plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/kLeqV/src/output.jl:169

The error message is not very clear and might confuse users, especially in longer or more complex code.

Would it be possible to improve the error handling here, perhaps with a more informative message, or catch the case where one or more inputs are empty?

System Information:

julia> versioninfo()
Julia Version 1.11.0
Commit 501a4f25c2b (2024-10-07 11:40 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 16 × Apple M3 Max
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m3)
Threads: 12 default, 0 interactive, 6 GC (on 12 virtual cores)

Possibly related issues: #1329, #448

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

1 participant