joshday / OnlineStats.jl

⚡ Single-pass algorithms for statistics
https://joshday.github.io/OnlineStats.jl/latest/
MIT License
831 stars 62 forks source link

HeatMap plot does not work when using plotlyjs #244

Closed schlichtanders closed 2 years ago

schlichtanders commented 2 years ago

the documentation example about HeatMap throws an error when I activate plotlyjs

using OnlineStats
using Plots
plotlyjs()   # without ploytljs() everything works

xy = zip(randn(10^6), randn(10^6))
o = fit!(HeatMap(-5:.1:5, -5:.1:5), xy)
plot(o)

xy = zip(1 .+ randn(10^6) ./ 10, randn(10^6))
o = HeatMap(xy)
plot(o, marginals=false)
plot(o)

it throws

BoundsError: attempt to access 199-element Vector{Float64} at index [1:200]

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] plotly_series_segments(series::Plots.Series, plotattributes_base::Dict{Symbol, Any}, x::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, y::Vector{Float64}, z::Nothing, clims::Tuple{Float64, Float64})
    @ Plots ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:873
  [5] plotly_series(plt::Plots.Plot{Plots.PlotlyBackend}, series::Plots.Series)
    @ Plots ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:606
  [6] #387
    @ ./array.jl:0 [inlined]
  [7] MappingRF
    @ ./reduce.jl:93 [inlined]
  [8] _foldl_impl(op::Base.MappingRF{Plots.var"#387#388"{Plots.Plot{Plots.PlotlyBackend}}, Base.BottomRF{typeof(vcat)}}, init::Base._InitialValue, itr::Vector{Plots.Series})
    @ Base ./reduce.jl:62
  [9] foldl_impl
    @ ./reduce.jl:48 [inlined]
 [10] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
 [11] #mapfoldl#214
    @ ./reduce.jl:160 [inlined]
 [12] mapfoldl
    @ ./reduce.jl:160 [inlined]
 [13] #mapreduce#218
    @ ./reduce.jl:287 [inlined]
 [14] mapreduce
    @ ./reduce.jl:287 [inlined]
 [15] #reduce#220
    @ ./reduce.jl:456 [inlined]
 [16] reduce
    @ ./reduce.jl:456 [inlined]
 [17] plotly_series
    @ ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:1034 [inlined]
 [18] plotly_series_json(plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:1038
 [19] js_body
    @ ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:1103 [inlined]
 [20] plotly_html_body(plt::Plots.Plot{Plots.PlotlyBackend}, style::Nothing)
    @ Plots ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:1091
 [21] plotly_html_body
    @ ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:1065 [inlined]
 [22] html_body
    @ ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:1043 [inlined]
 [23] embeddable_html
    @ ~/.julia/packages/Plots/qbc7U/src/backends/web.jl:26 [inlined]
 [24] _show(io::IOBuffer, #unused#::MIME{Symbol("text/html")}, plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots ~/.julia/packages/Plots/qbc7U/src/backends/plotly.jl:1123
 [25] show(io::IOBuffer, m::MIME{Symbol("text/html")}, plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots ~/.julia/packages/Plots/qbc7U/src/output.jl:213
 [26] sprint(::Function, ::MIME{Symbol("text/html")}, ::Vararg{Any, N} where N; context::Nothing, sizehint::Int64)
    @ Base ./strings/io.jl:105
 [27] sprint
    @ ./strings/io.jl:101 [inlined]
 [28] _ijulia_display_dict(plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots ~/.julia/packages/Plots/qbc7U/src/ijulia.jl:50
 [29] display_dict(plt::Plots.Plot{Plots.PlotlyBackend})
    @ Plots ~/.julia/packages/Plots/qbc7U/src/init.jl:93
 [30] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [31] invokelatest
    @ ./essentials.jl:706 [inlined]
 [32] execute_request(socket::ZMQ.Socket, msg::IJulia.Msg)
    @ IJulia ~/.julia/packages/IJulia/e8kqU/src/execute_request.jl:112
 [33] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [34] invokelatest
    @ ./essentials.jl:706 [inlined]
 [35] eventloop(socket::ZMQ.Socket)
    @ IJulia ~/.julia/packages/IJulia/e8kqU/src/eventloop.jl:8
 [36] (::IJulia.var"#15#18")()
    @ IJulia ./task.jl:411

juliaversioninfo()

Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, icelake-client)

(just seeing that I am running an old juliaversion, don't know whether this might be a reason)

joshday commented 2 years ago

What about with plotly() and gr()? If it works with other backends, this would probably be a Plots.jl issue.

schlichtanders commented 2 years ago

Indeed gr() works. Thank you for the push to go to plotlyjs to raise this.

Here is the new ticket: https://github.com/JuliaPlots/PlotlyJS.jl/issues/426