Makie Label

Is this supposed to work?

julia> let f = Figure()
           ax = Axis(f[1,1])
           Label(ax, "hello")
           f
       end
ERROR: MethodError: no method matching _block(::Type{Label}, ::Axis; text::String)

Closest candidates are:
  _block(::Type{<:Makie.Block}, ::Union{Figure, Scene}, ::Any, ::Dict, ::Any; kwdict_complete) got unsupported keyword argument "text"
   @ Makie ~/.julia/packages/Makie/z2T2o/src/makielayout/blocks.jl:308
  _block(::Type{<:Makie.Block}, ::Union{Figure, Scene}, Any...; bbox, kwargs...)
   @ Makie ~/.julia/packages/Makie/z2T2o/src/makielayout/blocks.jl:275
  _block(::Type{<:Makie.Block}, ::Union{GridPosition, GridSubposition}, Any...; kwargs...)
   @ Makie ~/.julia/packages/Makie/z2T2o/src/makielayout/blocks.jl:263

Stacktrace:
     â‹® internal @ Makie
 [2] Label(x::Axis, text::String; kwargs::@Kwargs{})
   @ Makie ~/.julia/packages/Makie/z2T2o/src/makielayout/blocks/label.jl:1

(@main) pkg> st CairoMakie
Status `~/.julia/environments/main/Project.toml`
  [13f3f980] CairoMakie v0.11.8

I don’t think so. The Label expects the position in the layout as first parameter. This works:

julia> let f = Figure()
           ax = Axis(f[1,1])
           Label(f[1,1], "hello")
           f
       end

See for example the Layout tutorial - Subplot Labels.

Edit: To put text on a plot (within an Axis) you should use text(!)

1 Like

If you’re looking for a title for an axis, you can set ax.title, or provide the title keyword

Why does Label take a position rather than an Axis? Would it make sense to allow it to take an axis?

“Why” is kind of a bad question :slightly_smiling_face: The authors of Makie chose to have a Block that just draws a text and call it Label. Other Blocks are for example Axis or Button or Textbox. You see Makie is half of a UI-Toolkit with which you can build quite interactive applications. Here is a list of all Blocks.

So you see a Label is not really meant for usage on a graph. It is it’s own indepent thing. If you just want to annotate a graph, i.e. but some text somewhere on the plot, then Label is not what you want to do. For annotation you should use the function text!

1 Like

Label is really just a wrapper around one text plot, with the wiring set up so that it’s dimensions can be communicated to the layout. This has overhead though, so you wouldn’t want every text in your plot to be a Label.

2 Likes