# Increase space between legend labels in Plots

**URL:** <https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474>\
**Category:** New to Julia\
**Tags:** plots\
**Created:** [June 6, 2021, 8:54pm UTC](https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474 "2021-06-06T20:54:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan.phi](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@Dan.phi](https://discourse.julialang.org/u/Dan.phi)\
**Post date:** [June 6, 2021, 8:54pm UTC](https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474/1 "2021-06-06T20:54:55Z")

</div>

Is there a way to increase the spacing between the legend labels in the histogram below so that they are legible? Thanks!

```julia
using LaTeXStrings

y1 = rand(100)
y2 = rand(100)
histogram(y1, ylims = (0,50), label = L"\left\Vert\beta_{1}^{2}-\beta_{2}^{2}\right\Vert")
histogram!(y2, label = L"\left\Vert\beta_{2}^{2}-\beta_{3}^{2}\right\Vert")

```

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

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [June 6, 2021, 11:53pm UTC](https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474/2 "2021-06-06T23:53:23Z")

</div>

If you use the `plotly()` backend: [latex - Julia plotting issues: label overlap and LaTeXStings expansion - Stack Overflow](https://stackoverflow.com/questions/61731322/julia-plotting-issues-label-overlap-and-latexstings-expansion)

I didn’t find a way to do it with the `gr()` backend. You can control the font with, say, `legendfontsize=14.0` and there is an option for `labelspacing=0.1` (typical values seem to be small), but I’m not sure what `labelspacing` actually does: it sounds like it might control the horizontal spacing, but I did not notice an effect on your plot. Hopefully someone from `Plots.jl` can help you with this. Alternatively, introducing a line skip inside the `LaTeX` string: I **also failed** to achieve that with the usual suspects: `"\\n"`, `"\\\"`, `"\\vspace{2em}"` 😳

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 7, 2021, 7:16pm UTC](https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474/3 "2021-06-07T19:16:11Z")

</div>

@Dan.phi, with Plots.jl you often need to be creative and it will rarely disappoint.

```julia
using LaTeXStrings, Plots; gr()

y1, y2 = rand(100), rand(100)
histogram(y1, ylims = (0,50), label = L"\left\Vert\beta_{1}^{2}-\beta_{2}^{2}\right\Vert")
scatter!([minimum(y1)],[0], label=" ", ms=0, mc=:white, msc=:white)
histogram!(y2, label = L"\left\Vert\beta_{2}^{2}-\beta_{3}^{2}\right\Vert", legendfontsize=10)

```

 ![Plots_gr_histograms_legend_space](https://global.discourse-cdn.com/julialang/original/3X/9/9/999ed822726a4c5bc3e21c07b59d6afb186b30e3.png)

_ **NB:** nevertheless, your code produces a legend that is perfectly legible in Julia 1.6.1, Win 10, Plots v1.16.3, gr backend_

 ![Plots_gr_legend_histograms](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff1797deaed2a5942cb4a89c16bcc76951288dbf.png)

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [June 7, 2021, 8:54pm UTC](https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474/4 "2021-06-07T20:54:47Z")

</div>

you added an invisible legend item with `scatter!` in order not to interfere with the other two `histogram` calls, right? Clever. 👍 This sort of trick is often needed.

I opened an [issue](https://github.com/JuliaPlots/Plots.jl/issues/3558) because I think it should not be too hard to add a padding option. There is such an option for the plot area itself and the legend is constructed in an analogous way. Unfortunately I don’t know enough about `Plots` to create a PR, but hopefully it’s a reasonable request.

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [July 3, 2021, 10:37pm UTC](https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474/5 "2021-07-03T22:37:16Z")

</div>

Huge thanks to @t-bltg, who in response to the issue mentioned above, put together a PR that allows more vertical space inside legends, fixing the OP and allowing more flexibility in general. 🙏

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [July 4, 2021, 10:25am UTC](https://discourse.julialang.org/t/increase-space-between-legend-labels-in-plots/62474/6 "2021-07-04T10:25:04Z")

</div>

Happy to help 😉
