# Resize legend box in subplots for Plots.jl?

**URL:** <https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [March 18, 2020, 1:23pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141 "2020-03-18T13:23:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [March 18, 2020, 1:23pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/1 "2020-03-18T13:23:59Z")

</div>

I have a series of subplots each with their own legend. however, the boxes around the legends are too big. how could I make them smaller? like, why is the red line in `avg N` so long?

 ![Screenshot 2020-03-18 14.18.24](https://global.discourse-cdn.com/julialang/original/3X/3/a/3a0f5aeca5bb0ef3b228a324d6f1136364481854.png)

asked differently: what determines the size of a box around a legend box in Plots.jl? they are all way to big here.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 18, 2020, 3:26pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/2 "2020-03-18T15:26:14Z")

</div>

Not the most helpful answer but it seems to me like they are all just the standard size that they would be in a regular plot, i.e. they don’t resize with the addition of subplots?

Maybe changing the legend fontsize helps?

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [March 18, 2020, 3:27pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/3 "2020-03-18T15:27:31Z")

</div>

no it does not ☹ (like, that decreases the font size alright, but the lines are much too long, and the markers are much too big). this doesn’t work very well for me.

---

<div class="post-metadata">

**Author:** ![josephmarturano](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@josephmarturano](https://discourse.julialang.org/u/josephmarturano)\
**Post date:** [March 19, 2020, 5:05pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/4 "2020-03-19T17:05:12Z")

</div>

I sympathize with this - I find the legend control in Plots.jl to be quite inadequate. I struggle with the legends every week. If anyone is aware of a Plots.jl legend tutorial showing all options, could you please share a link?

My usual strategy is to set some default and fairly large font sizes, like the following:

```julia
gr(size=(1200,1000), xtickfontsize=13, ytickfontsize=13, xguidefontsize=16, yguidefontsize=16, legendfontsize=10, dpi=100, grid=(:y, :gray, :solid, 1, 0.4));

```

And then for the final plot call (to bring together all of the subplots), I usually adjust the `size` argument until I am happy with the final look, e.g.:

```julia
plot(plot1, plot2, plot3, layout=(1,3), size=(2400,1000))

```

Have you tried a large plot `size` ?

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [March 19, 2020, 5:30pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/5 "2020-03-19T17:30:00Z")

</div>

hey, that sounds intriguing. no, i haven’t tried that! thanks for the hint i’ll give it a go.  
I’m working on an interactive plot, so I can’t really use pyplot (too slow). but that backend seems to handle the legend box _much_ better.

---

<div class="post-metadata">

**Author:** ![isentropic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/isentropic/32/11894_2.png) [@isentropic](https://discourse.julialang.org/u/isentropic)\
**Post date:** [April 25, 2020, 6:51am UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/6 "2020-04-25T06:51:08Z")

</div>

Legend box scales with `legendfontsize`, adjusting that adjusts the legend. You could specify the position of the legend manually. Try `plot(rand(3), legend=(3,3), legendfontsize=5)`

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [April 27, 2020, 2:35pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/7 "2020-04-27T14:35:48Z")

</div>

> [@isentropic](#):
>
> plot(rand(3), legend=(3,3), legendfontsize=5)

that’s not bad as a start! however, the size of the marker in the legend does not scale with that parameter. my problem is particularly acute with subplots, where I may have multiple lines per subplot. with your approach I can make the box of the legend smaller (which is great), but I get disproportionately big marker dots in the legend. shouldn’t the `markersize` map onto that legend dot?

```julia
x = rand(3)

julia> plot(x, legend=(.5,.5), legendfontsize=5, marker = (:circle,1),layout = (2,3))

```

 ![Screenshot 2020-04-27 16.33.12](https://global.discourse-cdn.com/julialang/original/3X/0/f/0f8cab14424049d255e6d81c987cc0705106e3d5.png)

```julia
julia> plot(x, legend=(.5,.5), legendfontsize=5, marker = (:circle,11),layout = (2,3))

```

 ![Screenshot 2020-04-27 16.33.28](https://global.discourse-cdn.com/julialang/original/3X/a/5/a506c9fc7ecb76792c71a33567aef64f54492332.png)

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [April 27, 2020, 2:41pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/8 "2020-04-27T14:41:17Z")

</div>

here is my real use case. the dots in the legend are just too big!

 ![multi-3-TS](https://global.discourse-cdn.com/julialang/original/3X/f/a/fa73af04302bbc1c0bcc3011d70370ceb9b69558.png)

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [May 29, 2021, 9:41pm UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/9 "2021-05-29T21:41:47Z")

</div>

One of the flaws that makes me consider Plots.jl not suitable (yet?) for publication quality plots.

---

<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:** [May 30, 2021, 12:41am UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/10 "2021-05-30T00:41:12Z")

</div>

Your actual use case could very well do without the balls in the legends.  
Colored lines seem to suffice and can be displayed alone in the legends, while keeping the balls in the subplots.

---

<div class="post-metadata">

**Author:** ![GaiaPet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gaiapet/32/44142_2.png) [@GaiaPet](https://discourse.julialang.org/u/GaiaPet)\
**Post date:** [November 4, 2022, 11:37am UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/11 "2022-11-04T11:37:23Z")

</div>

Hi! I found the “legendfontpointsize=” command that solves that! To be put inside plot(…)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/e/beff7e98af2cb399a011bb626c5f6bbcee7cbe4c.png)

---

<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:** [November 4, 2022, 11:47am UTC](https://discourse.julialang.org/t/resize-legend-box-in-subplots-for-plots-jl/36141/12 "2022-11-04T11:47:49Z")

</div>

Note that that keyword is the same as `legendfontsize`, about which OP was not happy with (_because of the size of legend lines and markers_).
