Common feature request for Plots.jl. It should be planned for early.
Could be implemented by making the legend a subplot in itself that can be placed either next to or superimposed to existing subplots - would be great for a shared legend for multi-subplot figures.
You can place the legend wherever you want already: http://makie.juliaplots.org/stable/legends.html
It might be nice in the simple functions to make that an attribute.
(offtopic - I can't see the video on that page on my mac - firefox/safari)
The link http://makie.juliaplots.org/stable/legends.html no longer works.
I'm trying to figure out how to add a legend to explain the colours for a 2D contour (mesh) plot.
I had my hopes up about the content I would find after having clicked that link. Can somebody please fix it? Otherwise, can somebody please tell me how to place the legend outside of the plotting area?
Hi,
I'm also trying to get legends to work, but so far no luck. What is the recommenced way of attaching a legend to a 2D line plot?
Sorry, I just added examples from home, but didn't push them :D will push them this evening!
Ah, just found one of the examples on my work PC:
using Makie
scene = Scene(resolution = (500, 500))
x = map([:dot, :dash, :dashdot], [2, 3, 4]) do ls, lw
linesegments!(
range(1, stop = 5, length = 100), rand(100), rand(100),
linestyle = ls, linewidth = lw,
color = rand(RGBAf0)
)[end]
end
x = [x..., scatter!(range(1, stop=5, length=100), rand(100), rand(100))[end]]
center!(scene)
ls = Makie.legend(x, ["attribute $i" for i in 1:4], camera = campixel!, raw = true)
vbox(scene, ls)

Cool, thanks! That works for me : )
Just a follow up, how would I go about creating a legend inside an existing plot? What I have attempted so far is to initially place the legend and plot side-by-side using the code above, and then using Makie.translate! on the plot to move it inside the plot. I encountered two issues with this. One is that the legend moves behind the plot instead, and the second is that the bounding box does not seem to update to reflect the fact that the legend has moved. Is there a recommended way of placing the legend inside the plot? Thanks!
-> MakieLayout
Most helpful comment
Could be implemented by making the legend a subplot in itself that can be placed either next to or superimposed to existing subplots - would be great for a shared legend for multi-subplot figures.