# GLMakie: Legend for figures with two y-axis

**URL:** <https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328>\
**Category:** General Usage\
**Tags:** plotting, glmakie\
**Created:** [January 29, 2026, 5:18pm UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328 "2026-01-29T17:18:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [January 29, 2026, 5:18pm UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/1 "2026-01-29T17:18:53Z")

</div>

Hi!  
I spent some time in the net but a failed to find a suitable solution.  
In the forum I found the helpful topic:  
[https://discourse.julialang.org/t/solved-plotting-2-plots-on-same-figure-with-dual-axis/124623](https://Plotting%202%20plots%20on%20same%20figure%20with%20dual%20axis)

But the question is still not solved:  
How to specify a legend if a figure contains two y-axis.  
Example:  
Given are: `Xvec, VectorDistValues, VectorCurrent, VectorPrivious`

```julia
    fig = Figure()
    ax1 = Axis(fig[1, 1], yticklabelcolor = :blue, xlabel = "n Iterations / -", ylabel = "Cycle Counter / -")
    ax2 = Axis(fig[1, 1], yticklabelcolor = :red, yaxisposition = :right, ylabel = "Distance / -")
    
    hln1 = lines!(ax1, Xvec, VectorDistValues, label= "Distance / -")
    hln2 = lines!(ax2, Xvec, VectorCurrent, color = :red, label= "Current")
    hln3 = lines!(ax2, Xvec, VectorPrivious, color = :orange, label= "Privious")  

```

I know that the following works fine:

```julia
    Legend(fig[1, 2],
       [hln1, hln2, hln3],
       ["Distance / -", "Current", "Privious"],)

```

But I wonder if I can use the line-labels already specified in the line-definitions.  
Something similar like the following (which works only for figures whith one y-axis):

```julia
    Legend(fig[1, 2], ax1)

```

Any ideas?

---

<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 29, 2026, 7:59pm UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/2 "2026-01-29T19:59:01Z")

</div>

You want [Add possibility to collect legend entries from multiple axes by jusack · Pull Request #5500 · MakieOrg/Makie.jl · GitHub](https://github.com/MakieOrg/Makie.jl/pull/5500)

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [January 30, 2026, 6:21am UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/3 "2026-01-30T06:21:48Z")

</div>

Cool! 🙂  
Thanks! - Is it already merged into main?

---

<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 30, 2026, 7:16am UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/4 "2026-01-30T07:16:23Z")

</div>

No, green means it’s still open

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [January 30, 2026, 10:25am UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/5 "2026-01-30T10:25:46Z")

</div>

@jules  
Proposal: What about an automatism: if there is a vector of axis handles join the legends of the axes?

---

<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 30, 2026, 10:27am UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/6 "2026-01-30T10:27:42Z")

</div>

Better to comment on the PR if you have specific suggestions about the implementation

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [April 8, 2026, 12:10pm UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/7 "2026-04-08T12:10:10Z")

</div>

@jules  
I was informed that something have been accepted and that code have been merged.  
Thanks for your initiative!  
What are now the next steps? Currently I do not yet see a change in the functionality of the `Legend()` function.

---

<div class="post-metadata">

**Author:** ![KristianHolme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristianholme/32/216911_2.png) [@KristianHolme](https://discourse.julialang.org/u/KristianHolme)\
**Post date:** [April 8, 2026, 2:22pm UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/8 "2026-04-08T14:22:37Z")

</div>

The PR is merged into the main branch of the [Makie.jl repo](https://github.com/MakieOrg/Makie.jl/) (see the [changelog](https://github.com/MakieOrg/Makie.jl/blob/master/CHANGELOG.md)), but is not released yet. It looks like the changes from the PR [#5551](https://github.com/MakieOrg/Makie.jl/pull/5551) will be released in Makie 0.24.10. In the meantime I think you can use the unreleased changes by doing

```julia
using Pkg
Pkg.add(url="https://github.com/MakieOrg/Makie.jl", rev="master")

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [April 8, 2026, 2:42pm UTC](https://discourse.julialang.org/t/glmakie-legend-for-figures-with-two-y-axis/135328/9 "2026-04-08T14:42:35Z")

</div>

Better is:  
`]add ComputePipeline#master Makie#master GLMakie#master`  
Since otherwise you may get some weird compat issues. ComputePipeline/Makie and the backends are developped in lockstep, and just adding `Makie#master` basically disables that 😉
