Resize legend box in subplots for Plots.jl?

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?

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

6 Likes

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?

no it does not :frowning: (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.

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:

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.:

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

Have you tried a large plot size ?

5 Likes

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.

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)

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?

x = rand(3)

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

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

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

3 Likes

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

3 Likes

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.

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

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).