I would like to create one legend for a layout plot in Julia. Here is some reproducible code:
using Plots plot(rand(100, 4), layout = 4, color = [:red :blue :green :yellow]) Output:
As you can see it shows nicely a legend to each subplot, but I would like to have one shared legend, using :shared doesn't work. So I was wondering if anyone knows how to add a shared legend to a layout plot in Julia?
1 Answer
Maybe this answer can give an idea. I can do it by a trick (creating a transparent plot for the legend). The only problem is that I don't know how I can move the legend (actually, the transparent plot) to the location I want:
colors = [:red :blue :green :yellow] p = [ plot(col, legend=false, color=colors[idx]) for (idx, col) in enumerate(eachcol(data)) ] p1 = plot((1:4)', legend=true, framestyle=:none, color=colors) plot( p..., p1, layout = @layout[ [ grid(2, 2) p ] p1 ], size = (1000, 1000) ) If I change the layout like the following:
layout = @layout[ p1 [ grid(2, 2) p ] ] # And change the order of the plots plot( p1, p..., ⋮ ) Note that I cropped the redundant area of the image above.
