# Legend with many labels can't fit in output

**URL:** <https://discourse.julialang.org/t/legend-with-many-labels-cant-fit-in-output/116947>\
**Category:** Visualization\
**Tags:** makie, cairomakie-plotting, cairomakie\
**Created:** [July 12, 2024, 6:54am UTC](https://discourse.julialang.org/t/legend-with-many-labels-cant-fit-in-output/116947 "2024-07-12T06:54:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AtomsForHire](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@AtomsForHire](https://discourse.julialang.org/u/AtomsForHire)\
**Post date:** [July 12, 2024, 6:54am UTC](https://discourse.julialang.org/t/legend-with-many-labels-cant-fit-in-output/116947/1 "2024-07-12T06:54:26Z")

</div>

Hello,

I have a plot with many lines, and a legend with labels for all those lines. Here is an example output.

```julia
using CairoMakie

set_theme!(theme_latexfonts())
update_theme!(
    palette=(color=ColorSchemes.glasbey_category10_n256.colors,),
    ScatterLines=(cycle=Cycle(:color),)
)
function main()
    f = Figure()
    ax = Axis(f[1, 1])

    for i in 1:30
        lines!(ax, 0:127, rand(128), label=string(i))
    end

    Legend(f[1, 2], ax, "Some Title", framevisible=false)
    ax.xlabel = "x-axis"
    ax.ylabel = "y-axis"

    resize_to_layout!(f)
    save("mwe.png", f)
end

main()

```

 ![mwe](https://global.discourse-cdn.com/julialang/original/3X/2/f/2ff25bc9b4a99bbd21d0b183741eb3cd7afcb1e3.jpeg)

I have tried the `resize_to_layout!()` and unfortunately it does not work, In python I could add the legend as an artist and the final output would automatically resize itself to fit in the whole legend. Is there a similar way to do it in Makie?

---

<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:** [July 12, 2024, 7:00am UTC](https://discourse.julialang.org/t/legend-with-many-labels-cant-fit-in-output/116947/2 "2024-07-12T07:00:12Z")

</div>

Add `tellheight = true` to the legend attributes. But maybe `nbanks = 2` would look better.

---

<div class="post-metadata">

**Author:** ![AtomsForHire](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@AtomsForHire](https://discourse.julialang.org/u/AtomsForHire)\
**Post date:** [July 12, 2024, 8:09am UTC](https://discourse.julialang.org/t/legend-with-many-labels-cant-fit-in-output/116947/3 "2024-07-12T08:09:49Z")

</div>

Thank you, I should have seen that earlier. And yes, nbanks=2 does help a lot!
