# Add line style to legend

**URL:** <https://discourse.julialang.org/t/add-line-style-to-legend/44667>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [August 10, 2020, 9:00am UTC](https://discourse.julialang.org/t/add-line-style-to-legend/44667 "2020-08-10T09:00:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [August 10, 2020, 9:00am UTC](https://discourse.julialang.org/t/add-line-style-to-legend/44667/1 "2020-08-10T09:00:19Z")

</div>

Is there a way to add something (in this case a line style) to a legend without plotting it? I am using `Plot.jl`

MWE

```julia
aa = 1:10
bb = 10 .* rand(10)
cc = 10 .* rand(10)
dd = 10 .* rand(10)
ee = 10 .* rand(10)
ff = 10 .* rand(10)
gg = 10 .* rand(10)

plot(aa, bb,color=1,label = "Cl 1")
plot!(aa,cc,color=1,ls=:dashdot,label = false)
plot!(aa,dd,color=2,label = "Cl 2")
plot!(aa,ee,color=2,ls=:dashdot,label = false)
plot!(aa,ff,color=3,label = "Cl 3")
plot!(aa,gg,color=3,ls=:dashdot,label = false)
plot!(colour = :black, label = "High") #this does nothing
plot!(colour = :black, ls=:dashdot, label = "Low") #this does nothing

```

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [August 14, 2020, 8:00am UTC](https://discourse.julialang.org/t/add-line-style-to-legend/44667/2 "2020-08-14T08:00:59Z")

</div>

I worked around it by first plotting black lines and then the rest of the plot on top of it. This results in some lines being darker than in the legend, but it works for now.

```julia
plot(aa, bb,colour = :black, label = "High")
plot!(aa,cc,colour = :black, ls=:dashdot, label = "Low")
plot!(aa, bb,color=1,label = "Cl 1")
plot!(aa,cc,color=1,ls=:dashdot,label = false)
plot!(aa,dd,color=2,label = "Cl 2")
plot!(aa,ee,color=2,ls=:dashdot,label = false)
plot!(aa,ff,color=3,label = "Cl 3")
plot!(aa,gg,color=3,ls=:dashdot,label = false)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/7/0/70d41362d6be2356b907ea86a52cd534d94617a5.png)

---

<div class="post-metadata">

**Author:** ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)\
**Post date:** [August 14, 2020, 8:33am UTC](https://discourse.julialang.org/t/add-line-style-to-legend/44667/3 "2020-08-14T08:33:42Z")

</div>

you could use `alpha=0.0`, or plot outside of the plot boundaries (use `xlims`, `ylims`)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 14, 2020, 1:45pm UTC](https://discourse.julialang.org/t/add-line-style-to-legend/44667/4 "2020-08-14T13:45:48Z")

</div>

The problem with `alpha = 0.0` is that the legend disappears though (as it uses the same transparency). I think plotting outside the area and fixing the `lims` or alternatively plotting a single point as a line - `plot!([0], [0])` - is the way to go
