How to set xlabel and ylabel in Makie recipe?

Is it possible to set the xlabel, ylabel and zlabel within a Makie recipe?

I am finishing a recipe for biplots, but can’t figure out how to set the labels of the axes to contain the variance explained. I would like to write Dim 1 (90%) in the xlabel for example:

I tried to add a Makie.xlabel!(plot, "foo") call inside the recipe but it errors:

ERROR: MethodError: no method matching getindex(::Combined{Biplots.biplot, Tuple{Matrix{Float64}}}, ::Type{OldAxis})
Closest candidates are:
  getindex(::AbstractPlot, ::Symbol) at /home/juliohm/.julia/packages/MakieCore/S8PkO/src/attributes.jl:188
  getindex(::AbstractPlot, ::UnitRange{var"#s14"} where var"#s14"<:Integer) at /home/juliohm/.julia/packages/MakieCore/S8PkO/src/attributes.jl:184
  getindex(::AbstractPlot, ::Integer) at /home/juliohm/.julia/packages/MakieCore/S8PkO/src/attributes.jl:183
  ...
Stacktrace:
 [1] xlabel!(scene::Combined{Biplots.biplot, Tuple{Matrix{Float64}}}, xlabel::String)

Here is the package with the recipe:

https://github.com/juliohm/Biplots.jl

I had the same question - unfortunately this thread is the first hit on google.

For those looking for the same answer:

Apparently what we want to do is not possible (yet, as of Jan 2023) as Makie recipes work on the “plot object level”, whereas the functions we want to use (ylabel!() etc) expect an Axis.

The closest I found is to provide an axis keyword to the recipe, which isn’t ideal.
Assuming biplot() is generated by a recipe, you should be able to do:

biplot(... ; axis=(ylabel="My Y-Axis label",))

Otherwise, it seems we have to define a custom plot function to do what we want, as suggested by @jules

Note also ylabel!() and xlabel!() does not currently work:

This is my current workaround

f = Figure()
ax = Axis(f[1,1])
series!(rand(7, 20))
ax.ylabel = "my y-axis label"

image

ax.ylabel =... is official api, not a workaround. We’ve not decided what attributes need additional setter functions, xlabel! and ylabel! used to work for different objects and weren’t updated. Not sure if it’s worth bringing them back if they do the same.

Ah okay, thanks!

Incidentally, if this is the official API, I ask that the docs for xlabel! and cousins be updated, as they are incorrect and the cause of the confusion above:

1 Like