# Makie read legend color

**URL:** <https://discourse.julialang.org/t/makie-read-legend-color/113076>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [April 17, 2024, 2:41pm UTC](https://discourse.julialang.org/t/makie-read-legend-color/113076 "2024-04-17T14:41:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rongcuid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rongcuid/32/42911_2.png) [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Post date:** [April 17, 2024, 2:41pm UTC](https://discourse.julialang.org/t/makie-read-legend-color/113076/1 "2024-04-17T14:41:46Z")

</div>

Is it possible to read back the colors from an existing Legend, or axis?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 17, 2024, 2:48pm UTC](https://discourse.julialang.org/t/makie-read-legend-color/113076/2 "2024-04-17T14:48:48Z")

</div>

I don’t quite understand, you want to know what colors the legend elements have?

---

<div class="post-metadata">

**Author:** ![rongcuid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rongcuid/32/42911_2.png) [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Post date:** [April 17, 2024, 2:51pm UTC](https://discourse.julialang.org/t/makie-read-legend-color/113076/3 "2024-04-17T14:51:48Z")

</div>

For instance, if I called two `lines!`:

```julia
fig = ...
ax = ...
lines!(ax, xs, label="A")
lines!(ax, ys, label="B")
legend = Legend(fig[1, 2], ax)

```

Now I would like to know what color is assigned to A and B

---

<div class="post-metadata">

**Author:** ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)\
**Post date:** [April 17, 2024, 6:12pm UTC](https://discourse.julialang.org/t/makie-read-legend-color/113076/4 "2024-04-17T18:12:42Z")

</div>

Is this what you need? `lines!` returns a line object that you can get the colour of by accessing `line.color`. The lines are contained in `ax.scene.plots`

```julia
fig = Figure()
ax = Axis(fig[1, 1])
l1=lines!(ax, rand(10), label="A")
l2=lines!(ax, rand(10), label="B")
legend = Legend(fig[1, 2], ax)

#from the lines:
l1.color[]
l2.color[]

#from the axis if you did not assign l1 and l2:
ax.scene.plots[1].color[]
ax.scene.plots[2].color[]

```
