# Colored legend with Makie

**URL:** <https://discourse.julialang.org/t/colored-legend-with-makie/30691>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [November 4, 2019, 1:09pm UTC](https://discourse.julialang.org/t/colored-legend-with-makie/30691 "2019-11-04T13:09:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Post date:** [November 4, 2019, 1:09pm UTC](https://discourse.julialang.org/t/colored-legend-with-makie/30691/1 "2019-11-04T13:09:26Z")

</div>

A have a colored scatterplot (made with Makie) and would like to make a legend that explains what the colors mean. How should I modify the following example to achieve this? Tried the kwargs suggested by the docs of `legend()`, but couldn’t get it to work.

```julia
using Makie
set1 = rand(Point3f0, 5)
set2 = rand(Point3f0, 5)
set3 = rand(Point3f0, 5)

sc = Scene()
scatter!(sc, set1, color=:blue)
scatter!(sc, set2, color=:red)
scatter!(sc, set3, color=:green)
texts = ["scene", "set1", "set2", "set3"]
colors = [:black, :blue, :red, :green]
sl = legend(sc, texts, color=colors)
vbox(sc, sl)

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 4, 2019, 1:59pm UTC](https://discourse.julialang.org/t/colored-legend-with-makie/30691/2 "2019-11-04T13:59:33Z")

</div>

This should work:

```julia
using Makie
set1 = rand(Point3f0, 5)
set2 = rand(Point3f0, 5)
set3 = rand(Point3f0, 5)

sc = Scene()
scatter!(sc, set1, color=:blue)
scatter!(sc, set2, color=:red)
scatter!(sc, set3, color=:green)
texts = ["set1", "set2", "set3"]
colors = [:black, :blue, :red, :green]
plots = sc.plots[2:end] # exclude axis, which is always plot 1
sl = legend(sc.plots[2:end], texts)
vbox(sc, sl)

```

---

<div class="post-metadata">

**Author:** ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Post date:** [November 4, 2019, 2:07pm UTC](https://discourse.julialang.org/t/colored-legend-with-makie/30691/3 "2019-11-04T14:07:49Z")

</div>

Thank you!
