# Makie - Defining legend output for a makie recipe

**URL:** https://discourse.julialang.org/t/makie-defining-legend-output-for-a-makie-recipe/121567
**Category:** Visualization
**Tags:** makie
**Created:** [October 22, 2024, 2:06am UTC](https://discourse.julialang.org/t/makie-defining-legend-output-for-a-makie-recipe/121567 "2024-10-22T02:06:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sc-dyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sc-dyer/32/209461_2.png) [@sc-dyer](https://discourse.julialang.org/u/sc-dyer)
#### Post date: [October 22, 2024, 2:06am UTC](https://discourse.julialang.org/t/makie-defining-legend-output-for-a-makie-recipe/121567/1 "2024-10-22T02:06:04Z")

</div>

Hi, I have a makie recipe that essentially makes a stacked line graph using the `band` function. A very simplified example of what this looks like is this:

```julia
function Makie.plot!(myplot::MyPlot)
    band!(myplot,myplot.x,0,myplot.y1,color=:red, label = "y1")
    band!(myplot,myplot.x,myplot.y1,myplot.y2,color=:blue, label = "y2")
    band!(myplot,myplot.x,myplot.y2,myplot.y3,color=:green, label = "y3")
end

```

I want to make a legend that shows the color of each of these bands with their label but I seem unable to do so. Instead, when I try to add a legend, I get the warning: `ERROR: There are no plots with labels in the given axis that can be put in the legend. Supply labels to plotting functions like `plot(args...; label = "My label")` `

I tried to play around with `legendelements` but I was pretty lost on how to make it do what I am trying to do or even if that is the appropriate function to use. Any advice on this would be greatly appreciated

---

<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: [October 22, 2024, 12:25pm UTC](https://discourse.julialang.org/t/makie-defining-legend-output-for-a-makie-recipe/121567/2 "2024-10-22T12:25:15Z")

</div>

I don’t think it was intended as public API, given that the name is not very descriptive, but there’s this internal function that for example `series` overloads to return its child plots for the legend gathering:

```julia
function Makie.get_plots(plot::Series)
    return plot.plots
end

```

---

<div class="post-metadata">

### Author: ![sc-dyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sc-dyer/32/209461_2.png) [@sc-dyer](https://discourse.julialang.org/u/sc-dyer)
#### Post date: [October 22, 2024, 4:39pm UTC](https://discourse.julialang.org/t/makie-defining-legend-output-for-a-makie-recipe/121567/3 "2024-10-22T16:39:46Z")

</div>

> [@jules](#):
>
> ```julia
> function Makie.get_plots(plot::Series)
> return plot.plots
> end
> 
> ```

Redefining this function for my plot type worked perfectly, thank you!

---

<div class="post-metadata">

### Author: ![hersle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hersle/32/211689_2.png) [@hersle](https://discourse.julialang.org/u/hersle)
#### Post date: [March 31, 2025, 6:50pm UTC](https://discourse.julialang.org/t/makie-defining-legend-output-for-a-makie-recipe/121567/4 "2025-03-31T18:50:03Z")

</div>

Is there a way to fix this when using `MakieCore` as a minimal dependency for recipes? Unfortunately, `MakieCore.get_plots` does not exist.

---

<div class="post-metadata">

### Author: ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)
#### Post date: [March 31, 2025, 10:28pm UTC](https://discourse.julialang.org/t/makie-defining-legend-output-for-a-makie-recipe/121567/5 "2025-03-31T22:28:53Z")

</div>

Could put it in a Makie extension, a la [Basic Package Extension Example](https://discourse.julialang.org/t/basic-package-extension-example/102969)
