Plots.jl icon indicating copy to clipboard operation
Plots.jl copied to clipboard

[BUG] Bar charts with vector attributes (e.g. multiple colors) broken in Plotly since v1.10.6

Open niclasmattsson opened this issue 1 year ago • 1 comments

This is partially the same issue as #4129, but I'm creating a new issue with a more descriptive title, more info on the problem including some version bisecting and a workaround that may be helpful. There may also be a separate problem related to #3623, https://github.com/JuliaPlots/StatsPlots.jl/issues/442 and the PR #3751 - these issues may have been prematurely closed as fixed.

Details

This is the part that is the same as #4129. This particular error was introduced sometime between Plots v1.22.5 and Plots v1.23.6.

julia> using Plots

julia> gr()
Plots.GRBackend()

julia> bar(rand(3), color=[:red, :green, :blue])  # works

julia> plotly()
Plots.PlotlyBackend()

julia> bar(rand(3), color=[:red, :green, :blue])
Error showing value of type Plots.Plot{Plots.PlotlyBackend}:
ERROR: ArgumentError: Iterates of the argument to Flatten are not known to have constant length
Stacktrace:
  [1] flatten_length(f::Base.Iterators.Flatten{Vector{Base.Generator{UnitRange{Int64}, Plots.var"#6#10"}}}, T::Type)
    @ Base.Iterators .\iterators.jl:1185
  [2] length(f::Base.Iterators.Flatten{Vector{Base.Generator{UnitRange{Int64}, Plots.var"#6#10"}}})
    @ Base.Iterators .\iterators.jl:1187
  [3] plotly_series_shapes(plt::Plots.Plot{Plots.PlotlyBackend}, series::Plots.Series, clims::Tuple{Float64, Float64})
    @ Plots C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:762
  [4] plotly_series(plt::Plots.Plot{Plots.PlotlyBackend}, series::Plots.Series)
    @ Plots C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:558
  [5] plotly_series(plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:1035
  [6] plotly_series_json
    @ C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:1041 [inlined]
  [7] js_body
    @ C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:1106 [inlined]
  [8] plotly_html_body(plt::Plots.Plot{Plots.PlotlyBackend}, style::Nothing)
    @ Plots C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:1094
  [9] plotly_html_body
    @ C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:1068 [inlined]
 [10] html_body
    @ C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:1046 [inlined]
 [11] #standalone_html#425
    @ C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\web.jl:10 [inlined]
 [12] write_temp_html(plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\web.jl:43
 [13] standalone_html_window(plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\web.jl:57
 [14] _display
    @ C:\Users\niclas\.julia\packages\Plots\PomtQ\src\backends\plotly.jl:1134 [inlined]
 [15] display(#unused#::Plots.PlotsDisplay, plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots C:\Users\niclas\.julia\packages\Plots\PomtQ\src\output.jl:148
 [16] display(x::Any)
    @ Base.Multimedia .\multimedia.jl:340
 [17] #invokelatest#2
    @ .\essentials.jl:816 [inlined]
 [18] invokelatest
    @ .\essentials.jl:813 [inlined]
 [19] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL C:\Julia\Julia-1.9.1\share\julia\stdlib\v1.9\REPL\src\REPL.jl:305
 [20] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL C:\Julia\Julia-1.9.1\share\julia\stdlib\v1.9\REPL\src\REPL.jl:287
 [21] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL C:\Julia\Julia-1.9.1\share\julia\stdlib\v1.9\REPL\src\REPL.jl:557
 [22] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL C:\Julia\Julia-1.9.1\share\julia\stdlib\v1.9\REPL\src\REPL.jl:285
 [23] (::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:\Julia\Julia-1.9.1\share\julia\stdlib\v1.9\REPL\src\REPL.jl:899
 [24] #invokelatest#2
    @ .\essentials.jl:816 [inlined]
 [25] invokelatest
    @ .\essentials.jl:813 [inlined]
 [26] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit C:\Julia\Julia-1.9.1\share\julia\stdlib\v1.9\REPL\src\LineEdit.jl:2647
 [27] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL C:\Julia\Julia-1.9.1\share\julia\stdlib\v1.9\REPL\src\REPL.jl:1300
 [28] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL .\task.jl:514

The error can be bypassed by defining a new Base.length() method for iterators. But this exposes another problem that may or may not be related:

julia> Base.length(f::Iterators.Flatten) = sum(length, f.it)

julia> bar(rand(3), color=[:red, :green, :blue])  # now produces a plot but with outlined bars without color fill

Again, the above has been the behavior since Plots v1.23.6. Versions of Plots between v1.11.0 - v1.22.5 did not have the iterator error, but instead produced several warnings like ┌ Warning: Indices Base.OneTo(3) of attribute *seriescolor* does not match data indices 1:17. and the resulting bars were all colored red (instead of white like now). The last working version with colored bars was Plots v1.10.6.

I also notice that Plotly doesn't have a line in the backend issue template just below (I entered it manually). Is Plotly no longer supported or is it just assumed identical to PlotlyJS? In any case, I wish Plotly would become a first-class citizen of Plots after v2.0 is released. For me it's by far the most interactive and easy to use backend.

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pythonplot x
plotly x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: see above Backend version (]st -m <backend(s)>): PlotlyBase v0.8.19 Output of versioninfo():

Julia Version 1.9.1
Commit 147bdf428c (2023-06-07 08:27 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × AMD Ryzen 9 6900HX with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
  Threads: 14 on 16 virtual cores
Environment:
  JULIA_EDITOR = "C:\Users\niclas\AppData\Local\Programs\Microsoft VS Code\Code.exe"
  JULIA_NUM_THREADS = 14
  JULIA_PKG_DEVDIR = C:\Stuff\Julia

niclasmattsson avatar Jun 20 '23 14:06 niclasmattsson

I also notice that Plotly doesn't have a line in the backend issue template just below (I entered it manually). Is Plotly no longer supported or is it just assumed identical to PlotlyJS?

They share most of the code, yes.

In any case, I wish Plotly would become a first-class citizen of Plots after v2.0 is released.

If you'd like to help with that, we can have a chat. Currently the position of a maintainer for the plotly stack is vacant.

BeastyBlacksmith avatar Jun 21 '23 09:06 BeastyBlacksmith