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

[BUG] can't plot with default colour scale with high precision floats #4270

Closed
dahtah opened this issue Jul 11, 2022 · 5 comments · Fixed by JuliaPlots/PlotUtils.jl#145
Closed
Labels

Comments

@dahtah
Copy link

dahtah commented Jul 11, 2022

There's an issue with the limits of the default colour scale when plotting with high precision floats (e.g. BigFloats).

Details

When plotting data that isn't Float64s but higher precision floats (like BigFloats, or ArbFloats from the ArbNumerics package), the following issue sometimes appears:

a=-exp(-BigFloat(8))
b=BigFloat(1)
heatmap([a b; b a]) 
#fails with
#ERROR: BoundsError: attempt to access 256-element Vector{Float64} at index [257]

Backends

Presumably all backends, this bug originates in colorschemes.jl

Versions

Plots.jl version: 1.31.1
Backend version (]st -m <backend(s)>): irrelevant
Output of versioninfo():
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
JULIA_ERROR_COLOR = magenta
JULIA_EDITOR = emacsclient

@dahtah dahtah added the bug label Jul 11, 2022
@t-bltg
Copy link
Member

t-bltg commented Jul 12, 2022

this bug originates in colorschemes.jl

If that is the case (it would be better to provide the full stacktrace), the bug should be reported to ColorSchemes.jl.

@nilshg
Copy link
Contributor

nilshg commented Jan 26, 2023

I think OP meant the files colorschemes.jl in PlotUtils - just had a user on Discourse run into this, here's the stacktrace:

julia> heatmap(rand(BigFloat, 200, 200))
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: BoundsError: attempt to access 256-element Vector{Float64} at index [257]
Stacktrace:
  [1] getindex
    @ .\essentials.jl:13 [inlined]
  [2] get(cg::PlotUtils.ContinuousColorGradient, x::BigFloat, rangescale::Tuple{Float64, Float64})
    @ PlotUtils C:\Users\ngudat\.julia\packages\PlotUtils\M092a\src\colorschemes.jl:68
  [3] (::PlotUtils.var"#6#7"{PlotUtils.ContinuousColorGradient})(x::BigFloat)
    @ PlotUtils C:\Users\ngudat\.julia\packages\PlotUtils\M092a\src\colorschemes.jl:29
  [4] iterate
    @ .\generator.jl:47 [inlined]
  [5] collect_to!(dest::Matrix{RGBA{BigFloat}}, itr::Base.Generator{Matrix{BigFloat}, PlotUtils.var"#6#7"{PlotUtils.ContinuousColorGradient}}, offs::Int64, st::Int64)
    @ Base .\array.jl:840
  [6] collect_to_with_first!(dest::Matrix{RGBA{BigFloat}}, v1::RGBA{BigFloat}, itr::Base.Generator{Matrix{BigFloat}, PlotUtils.var"#6#7"{PlotUtils.ContinuousColorGradient}}, st::Int64)
    @ Base .\array.jl:818
  [7] _collect(c::Matrix{BigFloat}, itr::Base.Generator{Matrix{BigFloat}, PlotUtils.var"#6#7"{PlotUtils.ContinuousColorGradient}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{2})
    @ Base .\array.jl:812
  [8] collect_similar
    @ .\array.jl:711 [inlined]
  [9] map
    @ .\abstractarray.jl:3255 [inlined]
 [10] get(cg::PlotUtils.ContinuousColorGradient, v::Matrix{BigFloat}, rangescale::Tuple{Float64, Float64})
    @ PlotUtils C:\Users\ngudat\.julia\packages\PlotUtils\M092a\src\colorschemes.jl:29
 [11] gr_draw_heatmap(series::Plots.Series, x::Vector{Float64}, y::Vector{Float64}, z::Matrix{BigFloat}, clims::Tuple{Float64, Float64})
    @ Plots C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:1954
 [12] gr_add_series(sp::Plots.Subplot{Plots.GRBackend}, series::Plots.Series)
    @ Plots C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:1728
 [13] gr_display(sp::Plots.Subplot{Plots.GRBackend}, w::Measures.AbsoluteLength, h::Measures.AbsoluteLength, vp_canvas::Plots.GRViewport{Float64})
    @ Plots C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:956
 [14] (::Plots.var"#528#529"{Int64, Int64, Plots.GRViewport{Float64}})(sp::Plots.Subplot{Plots.GRBackend})
    @ Plots C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:680
 [15] foreach(f::Plots.var"#528#529"{Int64, Int64, Plots.GRViewport{Float64}}, itr::Vector{Plots.Subplot})
    @ Base .\abstractarray.jl:3067
 [16] gr_display(plt::Plots.Plot{Plots.GRBackend}, dpi_factor::Int64)
    @ Plots C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:680
 [17] gr_display
    @ C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:650 [inlined]
 [18] #574
    @ C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:2044 [inlined]
 [19] withenv(::Plots.var"#574#576"{Plots.Plot{Plots.GRBackend}}, ::Pair{String, String}, ::Vararg{Pair{String}})
    @ Base .\env.jl:197
 [20] _display(plt::Plots.Plot{Plots.GRBackend})
    @ Plots C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\backends\gr.jl:2043
 [21] display(#unused#::Plots.PlotsDisplay, plt::Plots.Plot{Plots.GRBackend})
    @ Plots C:\Users\ngudat\.julia\packages\Plots\nuwp4\src\output.jl:174
 [22] display(x::Any)
    @ Base.Multimedia .\multimedia.jl:340
 [23] #invokelatest#2
    @ .\essentials.jl:816 [inlined]
 [24] invokelatest
    @ .\essentials.jl:813 [inlined]
 [25] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL C:\Users\ngudat\AppData\Local\Programs\Julia-1.9.0-beta3\share\julia\stdlib\v1.9\REPL\src\REPL.jl:302
 [26] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL C:\Users\ngudat\AppData\Local\Programs\Julia-1.9.0-beta3\share\julia\stdlib\v1.9\REPL\src\REPL.jl:284
 [27] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL C:\Users\ngudat\AppData\Local\Programs\Julia-1.9.0-beta3\share\julia\stdlib\v1.9\REPL\src\REPL.jl:551
 [28] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL C:\Users\ngudat\AppData\Local\Programs\Julia-1.9.0-beta3\share\julia\stdlib\v1.9\REPL\src\REPL.jl:282
 [29] (::REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL C:\Users\ngudat\AppData\Local\Programs\Julia-1.9.0-beta3\share\julia\stdlib\v1.9\REPL\src\REPL.jl:893
 [30] #invokelatest#2
    @ .\essentials.jl:816 [inlined]
 [31] invokelatest
    @ .\essentials.jl:813 [inlined]
 [32] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit C:\Users\ngudat\AppData\Local\Programs\Julia-1.9.0-beta3\share\julia\stdlib\v1.9\REPL\src\LineEdit.jl:2644
 [33] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL C:\Users\ngudat\AppData\Local\Programs\Julia-1.9.0-beta3\share\julia\stdlib\v1.9\REPL\src\REPL.jl:1293
 [34] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL .\task.jl:514

@t-bltg
Copy link
Member

t-bltg commented Jan 26, 2023

@nilshg
Copy link
Contributor

nilshg commented Jan 26, 2023

Hm, you're right - it only errors when one adds AssociatedLegendrePolynomials and SpecialFunctions to the environment - maybe that restricts some transitive dependency to an older version? Plots is at 1.38.2 in both cases.

@t-bltg
Copy link
Member

t-bltg commented Jan 26, 2023

However OP's example errors on current PlotUtils and latest Plots.
Will try to fix.

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

Successfully merging a pull request may close this issue.

3 participants