# Plots.jl attributes can be broadcasted? Changing linestyle for example

**URL:** <https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559>\
**Category:** General Usage\
**Tags:** plotting, graphics\
**Created:** [January 12, 2019, 1:55pm UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559 "2019-01-12T13:55:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [January 12, 2019, 1:55pm UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/1 "2019-01-12T13:55:12Z")

</div>

Hi,

When using `Plots`, I can specify the color like

```julia
using Plots
ls = vcat(fill(:red,5),fill(:green,5))
plot(rand(10),linecolor = ls)

```

but somehow this does not work

```julia
ls = vcat(fill(:dash,5),fill(:solid,5))
plot(rand(10),linestyle = ls)

```

How can I make it work?

Also, what are the attributes that accept a vector of values?

Thank you for your help,

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [January 26, 2019, 8:32am UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/2 "2019-01-26T08:32:03Z")

</div>

Is there a proper way or do I have to plot several line segments with `linestyle` specified with a single element?

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [January 27, 2019, 4:38pm UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/3 "2019-01-27T16:38:13Z")

</div>

This appears to be one of the fancier features of Plots. Not all backends are likely to support it because it is not necessarily a use case that many backend developpers might have anticipated/understood (I know InspectDR does not support this feature - not even for a color change).

I must also say that this is somewhat of an ambiguous command. For example, most backends would have to pick a single line color for their legends. To be accurate, a legend should probably display a similar color/line pattern that corresponds to the drawn line.

In any case, if I were to generate a plot similar to what you want, I would break up the datasets into multiple subsets (vectors), and assign a particular color/linestyle to that particular subset. In this particular case, that would just be 2 subsets.

The alternative would be to contribute changes to the Plots.jl module in order to support this feature.

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [February 5, 2019, 7:59am UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/4 "2019-02-05T07:59:44Z")

</div>

> [@MA\_Laforge](#):
>
> In any case, if I were to generate a plot similar to what you want, I would break up the datasets into multiple subsets (vectors), and assign a particular color/linestyle to that particular subset. In this particular case, that would just be 2 subsets.

This is what I wanted to hear. Thank you for your answer

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 5, 2019, 2:52pm UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/5 "2019-02-05T14:52:55Z")

</div>

Sorry, didn’t see this. Is what you’re looking for

```julia
grs = [ones(5); 2ones(5)]
plot(rand(10), group = grs, linestyle = :auto)

```

![ex](https://global.discourse-cdn.com/julialang/original/3X/1/e/1e4cb1213b221d6d7d17da60a987657d7f08926e.png)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [September 5, 2019, 3:36pm UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/6 "2019-09-05T15:36:39Z")

</div>

no, it should be the result of this

```julia
N = 5
x=1:(2N)
y=rand(N*2)
st = vcat(fill(:dot,N),fill(:solid,N))
plot(y, linestyle = st)
plot(y[1:N],linestyle=:dot, color=:blue)
plot!(N:2N,y[N:end],linestyle=:solid,color=:blue,label="")

```

 ![10](https://global.discourse-cdn.com/julialang/original/3X/c/e/ce16306d920faad7217d05b13e38ac0b22134c8d.png)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [September 9, 2019, 4:31pm UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/7 "2019-09-09T16:31:18Z")

</div>

@mkborregaard Should I implement this myself or is it part of `Plots`?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 10, 2019, 6:05am UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/8 "2019-09-10T06:05:21Z")

</div>

It should be supported, and it’s a bug that it isn’t. I would have thought this functionality was added in @daschw 's “easter special” PR: [https://github.com/JuliaPlots/Plots.jl/pull/1467](https://github.com/JuliaPlots/Plots.jl/pull/1467)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [September 10, 2019, 6:27am UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/9 "2019-09-10T06:27:09Z")

</div>

@mkborregaard

Yes it should be… I put a comment there and I tried to corner the bug a bit more.

---

<div class="post-metadata">

**Author:** ![daschw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daschw/32/2926_2.png) [@daschw](https://discourse.julialang.org/u/daschw)\
**Post date:** [September 10, 2019, 7:34am UTC](https://discourse.julialang.org/t/plots-jl-attributes-can-be-broadcasted-changing-linestyle-for-example/19559/10 "2019-09-10T07:34:33Z")

</div>

Fixed in [https://github.com/JuliaPlots/Plots.jl/pull/2180](https://github.com/JuliaPlots/Plots.jl/pull/2180), thanks for reporting!
