Problem with annotations!() in Makie

This snippet:

using AbstractPlotting, Makie, Random

scene = Scene(resolution = (1200, 1500))
poly = Vec2f0.(1:10, rand(10))
labels = ["$i" for i in 1:10]
scatter!(scene, poly, color = :blue)
annotations!(scene, labels, poly, textsize = 0.01, color = :green)
display(scene)

produces:

ERROR: LoadError: BoundsError: attempt to access String
  at index [2]
Stacktrace:
 [1] indexed_iterate(::String, ::Int64, ::Int64) at ./tuple.jl:90
 [2] (::AbstractPlotting.var"#387#389"{SArray{Tuple{4,4},Float32,2,16},Base.GenericIOBuffer{Array{UInt8,1}},Array{Point{3,Float32},1},Array{ColorTypes.RGBA{Float32},1},Array{Float32,1},Array{FreeTypeAbstraction.FTFont,1},Array{Quaternion{Float32},1}})(::Int64, ::FreeTypeAbstraction.FTFont, ::String, ::Symbol, ::Float64, ::Tuple{Symbol,Symbol}, ::Float64, ::Float64, ::Float64) at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/basic_recipes/basic_recipes.jl:415
 [3] broadcast_foreach(::Function, ::UnitRange{Int64}, ::Vararg{Any,N} where N) at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/utilities/utilities.jl:156
 [4] (::AbstractPlotting.var"#386#388"{Array{Point{3,Float32},1},Array{ColorTypes.RGBA{Float32},1},Array{Float32,1},Array{FreeTypeAbstraction.FTFont,1},Array{Quaternion{Float32},1},Combined{AbstractPlotting.text,Tuple{String}}})(::SArray{Tuple{4,4},Float32,2,16}, ::String, ::Array{String,1}, ::Symbol, ::Vararg{Any,N} where N) at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/basic_recipes/basic_recipes.jl:413
 [5] (::Observables.OnUpdate{AbstractPlotting.var"#386#388"{Array{Point{3,Float32},1},Array{ColorTypes.RGBA{Float32},1},Array{Float32,1},Array{FreeTypeAbstraction.FTFont,1},Array{Quaternion{Float32},1},Combined{AbstractPlotting.text,Tuple{String}}},Tuple{Observable{Any},Observable{Any},Observable{Array{String,1}},Observable{Any},Observable{Any},Observable{Any},Observable{Any},Observable{Any},Observable{Any}}})(::SArray{Tuple{4,4},Float32,2,16}) at /home/paul/.julia/packages/Observables/0wrF6/src/Observables.jl:218
 [6] setindex!(::Observable{Any}, ::SArray{Tuple{4,4},Float32,2,16}; notify::Observables.var"#6#8") at /home/paul/.julia/packages/Observables/0wrF6/src/Observables.jl:130
 [7] setindex!(::Observable{Any}, ::SArray{Tuple{4,4},Float32,2,16}) at /home/paul/.julia/packages/Observables/0wrF6/src/Observables.jl:126
 [8] notify!(::Observable{Any}) at /home/paul/.julia/packages/Observables/0wrF6/src/Observables.jl:72
 [9] plot!(::Combined{AbstractPlotting.annotations,Tuple{Array{String,1},Array{SArray{Tuple{2},Float32,1,2},1}}}) at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/basic_recipes/basic_recipes.jl:432
 [10] plot!(::Scene, ::Type{Combined{AbstractPlotting.annotations,Tuple{Array{String,1},Array{SArray{Tuple{2},Float32,1,2},1}}}}, ::Attributes, ::Tuple{Observable{Array{String,1}},Observable{Array{SArray{Tuple{2},Float32,1,2},1}}}, ::Observable{Tuple{Array{String,1},Array{SArray{Tuple{2},Float32,1,2},1}}}) at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:651
 [11] plot!(::Scene, ::Type{Combined{AbstractPlotting.annotations,ArgType} where ArgType}, ::Attributes, ::Array{String,1}, ::Vararg{Any,N} where N; kw_attributes::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:580
 [12] plot! at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:549 [inlined]
 [13] #annotations!#378 at /home/paul/.julia/packages/AbstractPlotting/q9DyS/src/recipes.jl:23 [inlined]
 [14] top-level scope at /home/paul/st/julia/err5.jl:7
 [15] include_string(::Module, ::String, ::String) at ./loading.jl:1080
in expression starting at /home/paul/st/julia/err5.jl:7

Looking at documentation https://makie.juliaplots.org/dev/abstractplotting_api.html#AbstractPlotting.annotations!-Tuple it seems that arguments to annotations! are OK. Can someone point me in the right direction?

Changing poly type from Array{Vec{2,Float32},1} to Array{Point{2,Float64},1}, i.e.:

poly = Point.(1:10, rand(10))

produces expected behavior.

1 Like