Single legend multiple plots - Plots, pyplot()


I am putting together 4 scatter plots that contain the same variables, so I would like 1 unique legend at the bottom of the plot. The following code generates one legend per graph

s1 = scatter(collect(1:10),collect(1:10))
s2 = scatter(collect(1:10),collect(1:10))
s3 = scatter(collect(1:10),collect(1:10))
s4 = scatter(collect(1:10),collect(1:10))


Just add legend = :none to three of the calls? (on a phone so can’t verify that that’s the right kwarg…

Thanks. It is a partial solution, because it leaves the legend on one of them. I would like the legend to be on none of them, and place it on a separate line below the plot

Ah right - I think there’s a keyword similar to legend = :outerright that puts the legend outside the plot

You can also keep the legend in a separate plot:

s1 = scatter(1:10, 1:10, legend = false)
s2 = scatter(1:10, 1:10, legend = false)
s3 = scatter(1:10, 1:10, legend = false)
s4 = scatter(1:10, 1:10, legend = false)
legend = plot([0 0 0 0], showaxis = false, grid = false, label = ["s1" "s2" "s3" "s4"])
plot(s1, s2, s3, s4, legend, layout = @layout([[A B; C D] E{.1w}]))

Edit: Made it slightly more compact.

1 Like

Thanks, this is helping a lot. Since I want to have the legend in the middle, I created a other two empty subplots, and I placed the one with the legend in the middle. This still leave a lot of white space under the figure. How can I adjust the size of each subplot? Also, how can I have the entries of the legend aligned horizontally?