# Julia PyPlot: how to assign multiple colors to legend

**URL:** https://discourse.julialang.org/t/julia-pyplot-how-to-assign-multiple-colors-to-legend/50177
**Category:** New to Julia
**Created:** [November 15, 2020, 8:54am UTC](https://discourse.julialang.org/t/julia-pyplot-how-to-assign-multiple-colors-to-legend/50177 "2020-11-15T08:54:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [November 15, 2020, 8:54am UTC](https://discourse.julialang.org/t/julia-pyplot-how-to-assign-multiple-colors-to-legend/50177/1 "2020-11-15T08:54:11Z")

</div>

Hello,  
I am assigning the color of a plot drawn with PyPlot manually, I need to assign the same color to the legend. How can I control the color parameter?  
I am using the following but it gives me an error:

```julia
legend(["A", "B", "C"], 
    color = ["blue", "red", "green"],
    loc="best")

```

What is the correct syntax?  
Thank you

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [November 15, 2020, 1:59pm UTC](https://discourse.julialang.org/t/julia-pyplot-how-to-assign-multiple-colors-to-legend/50177/2 "2020-11-15T13:59:23Z")

</div>

if you’re looking to color the text in the legend, one way to do it by looping over the text objects after creating the legend.

```julia
l = legend(["A", "B", "C"], loc="best")

for t in l.get_texts()
    if t.get_text() == "A"
        setp(t, color="blue")
    elseif t.get_text() == "B"
        setp(t, color="red")
    elseif t.get_text() == "C"
        setp(t, color="green")
    end
end

```

The loop may be condensed using broadcasting:

```julia
((t,c)->setp(t, color=c)).(l.get_texts(), ["blue", "red", "green"]);

```

---

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [November 15, 2020, 5:00pm UTC](https://discourse.julialang.org/t/julia-pyplot-how-to-assign-multiple-colors-to-legend/50177/3 "2020-11-15T17:00:55Z")

</div>

Thank you, but the color of text I found I could change it directly with `labelcolor = ["blue", "red", "green"]`.  
I am looking for the same construct but for the color of the lines (and, prospectively, the icons)…
