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

Hi,

When using Plots, I can specify the color like

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

but somehow this does not work

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,

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

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.

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

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

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

ex

no, it should be the result of this

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="")

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

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

@mkborregaard

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

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

2 Likes