I want to plot vertical lines on an axis by passing vlines! an observable to a vector with positions. In my intended use case, the vector will initially be empty. This works fine when I explicitly specify the axis boundaries. Here is a short code example:
using GLMakie
f = Figure()
display(f)
ax = Axis(f[1, 1])
limits!(ax, 0.0f0, 10.0f0, 0.0f0, 10.0f0) # same values as default values
println(ax.xaxis.attributes.limits.val) # prints (0.0f0, 10.0f0)
println(ax.yaxis.attributes.limits.val) # prints (0.0f0, 10.0f0)
positions = Observable{Vector{Float32}}([])
vlines!(ax, positions)
However, if I do not explicitly specify the axis limits, the same procedure throws a MethodError when running Julia v1.10.2 and GLMakie v0.9.9.
using GLMakie
f = Figure()
display(f)
ax = Axis(f[1, 1])
println(ax.xaxis.attributes.limits.val) # prints (0.0f0, 10.0f0)
println(ax.yaxis.attributes.limits.val) # prints (0.0f0, 10.0f0)
positions = Observable{Vector{Float32}}([])
vlines!(ax, positions)
ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
[1] reduce_empty(op::Base.MappingRF{Base.ExtremaMap{typeof(identity)}, typeof(Base._extrema_rf)}, ::Type{Float32})
@ Base ./reduce.jl:361
[2] reduce_empty_iter
@ ./reduce.jl:384 [inlined]
[3] mapreduce_empty_iter(f::Function, op::Function, itr::Vector{Float32}, ItrEltype::Base.HasEltype)
@ Base ./reduce.jl:380
[4] _mapreduce(f::Base.ExtremaMap{typeof(identity)}, op::typeof(Base._extrema_rf), ::IndexLinear, A::Vector{Float32})
@ Base ./reduce.jl:432
[5] _mapreduce_dim
@ ./reducedim.jl:365 [inlined]
[6] mapreduce
@ ./reducedim.jl:357 [inlined]
[7] _extrema
@ ./reducedim.jl:1015 [inlined]
[8] _extrema
@ ./reducedim.jl:1014 [inlined]
[9] extrema(a::Vector{Float32})
@ Base ./reducedim.jl:1010
[10] data_limits(p::Plot{Makie.vlines, Tuple{Vector{Float32}}})
@ Makie ~/.julia/packages/Makie/VRavR/src/basic_recipes/hvlines.jl:104
[11] (::Makie.var"#936#938"{Makie.var"#exclude#1639"{…}, Base.RefValue{…}})(plot::Plot{Makie.vlines, Tuple{…}})
@ Makie ~/.julia/packages/Makie/VRavR/src/layouting/data_limits.jl:225
[12] foreach(f::Makie.var"#936#938"{Makie.var"#exclude#1639"{…}, Base.RefValue{…}}, itr::Vector{AbstractPlot})
@ Base ./abstractarray.jl:3097
[13] foreach_plot
@ ~/.julia/packages/Makie/VRavR/src/layouting/data_limits.jl:108 [inlined]
[14] foreach_plot
@ ~/.julia/packages/Makie/VRavR/src/layouting/data_limits.jl:102 [inlined]
[15] data_limits
@ ~/.julia/packages/Makie/VRavR/src/layouting/data_limits.jl:223 [inlined]
[16] getlimits(la::Axis, dim::Int64)
@ Makie ~/.julia/packages/Makie/VRavR/src/makielayout/blocks/axis.jl:843
[17] autolimits(ax::Axis, dim::Int64)
@ Makie ~/.julia/packages/Makie/VRavR/src/makielayout/blocks/axis.jl:920
[18] xautolimits
@ ~/.julia/packages/Makie/VRavR/src/makielayout/blocks/axis.jl:951 [inlined]
[19] reset_limits!(ax::Axis; xauto::Bool, yauto::Bool, zauto::Bool)
@ Makie ~/.julia/packages/Makie/VRavR/src/makielayout/blocks/axis.jl:572
[20] reset_limits!
@ ~/.julia/packages/Makie/VRavR/src/makielayout/blocks/axis.jl:559 [inlined]
[21] plot!(ax::Axis, plot::Plot{Makie.vlines, Tuple{Vector{Float32}}})
@ Makie ~/.julia/packages/Makie/VRavR/src/figureplotting.jl:321
[22] _create_plot!(::Function, ::Dict{Symbol, Any}, ::Axis, ::Observable{Vector{Float32}})
@ Makie ~/.julia/packages/Makie/VRavR/src/figureplotting.jl:284
[23] vlines!(::Axis, ::Vararg{Any}; kw::@Kwargs{})
@ Makie ~/.julia/packages/MakieCore/UAwps/src/recipes.jl:176
[24] top-level scope
@ Untitled-1:12
Some type information was truncated. Use `show(err)` to see complete types.
While I can work around this problem, I wonder if this behavior is intentional or rather a bug, because in the example above, the axis limits that I explicitly set are identical to the default values that are used when the axis limits are not explicitly set.