# How to set xlabel and ylabel in Makie recipe?

**URL:** <https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279>\
**Category:** Visualization\
**Tags:** plotting, makie, recipe\
**Created:** [September 16, 2021, 5:58pm UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279 "2021-09-16T17:58:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 16, 2021, 5:58pm UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279/1 "2021-09-16T17:58:48Z")

</div>

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:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/4/d48f4e7d218b0a7f99428a0759435bcae0f4e846.png)

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

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 16, 2021, 6:26pm UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279/2 "2021-09-16T18:26:17Z")

</div>

Here is the package with the recipe:

[https://github.com/juliohm/Biplots.jl](https://github.com/juliohm/Biplots.jl)

---

<div class="post-metadata">

**Author:** ![ConnectedSystems](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/connectedsystems/32/16815_2.png) [@ConnectedSystems](https://discourse.julialang.org/u/ConnectedSystems)\
**Post date:** [January 6, 2023, 12:17am UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279/3 "2023-01-06T00:17:53Z")

</div>

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.

> [@Makie plot recipe collections?](https://discourse.julialang.org/t/makie-plot-recipe-collections/86434/2):
>
> Just scattered across different repositories, there is no central recipe repo aside from Makie.jl. Makie recipes currently only work on the plot object level and cannot modify Axis, Colorbar, etc. Therefore we don’t have so many recipes yet, which usually involve axis labels etc when you look for example at the Plots.jl ecosystem.

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

> [@Makie: Combine plots into subplots](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280/4):
>
> What I often do currently, because we don’t have subplot level recipes yet, is to make a function that receives either a Figure or a FigurePosition. If there’s no input argument, a new figure is created. This then works for both the single figure and subplot case. function myplot(f = Figure()) Axis(f[1, 1]) Colorbar(f[1, 2]) f end myplot() myplot(some\_figure[1:2, 3])

---

<div class="post-metadata">

**Author:** ![ConnectedSystems](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/connectedsystems/32/16815_2.png) [@ConnectedSystems](https://discourse.julialang.org/u/ConnectedSystems)\
**Post date:** [January 6, 2023, 12:41am UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279/4 "2023-01-06T00:41:41Z")

</div>

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

> <https://github.com/MakieOrg/Makie.jl/issues/1808>
>
> When using \`xlabel!\` or \`ylabel!\` to set axis labels according to the docstring,… Makie throws a method error.
> 
> \`\`\`julia
> using CairoMakie
> 
> lines(0:0.1:2π, sin)
> xlabel!("My X Label")
> \`\`\`
> 
> \`\`\` julia
> MethodError: no method matching xlabel!(::String)
> 
> Closest candidates are:
> 
> xlabel!(::Any, !Matched::AbstractString)
> \`\`\`
> 
> In the source, \`xlabel!\` requires a \`scene\` positional argument. This conflicts with the docstring which specifies it as optional.
> 
> https://github.com/JuliaPlots/Makie.jl/blob/84a026f5a59ee71df50f2486be89da27a41af82d/src/shorthands.jl#L7-L18
> 
> From the \[documentation\](https://makie.juliaplots.org/v0.15.2/documentation/scenes/), it seems like \`scene\`s where phased out in favor of \`Figure\`s. Also this \[discourse post\](https://discourse.julialang.org/t/makie-xlabel/53905) further describes the same issue.
> 
> If this is a valid issue, I don't mind creating a draft pull request simply implementing a method for \`xlabel!(xlabel::AbstractString)\`.

This is my current workaround

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

```

![image](https://global.discourse-cdn.com/julialang/original/3X/2/d/2d5baaf512e2360aab6c36dda96861d50fa2af57.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 6, 2023, 8:47am UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279/5 "2023-01-06T08:47:41Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![ConnectedSystems](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/connectedsystems/32/16815_2.png) [@ConnectedSystems](https://discourse.julialang.org/u/ConnectedSystems)\
**Post date:** [January 6, 2023, 9:02am UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279/6 "2023-01-06T09:02:33Z")

</div>

Ah okay, thanks!

---

<div class="post-metadata">

**Author:** ![ConnectedSystems](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/connectedsystems/32/16815_2.png) [@ConnectedSystems](https://discourse.julialang.org/u/ConnectedSystems)\
**Post date:** [January 8, 2023, 11:13pm UTC](https://discourse.julialang.org/t/how-to-set-xlabel-and-ylabel-in-makie-recipe/68279/7 "2023-01-08T23:13:36Z")

</div>

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:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/a/0ad9c01821c0286f95d9e984dac78829decbd827.png)
