how does one label two lines?
using Plots; pyplot()
plot(Plots.fakedata(50,2), w=3, labels=[ "a", "b" ])
the blue line is not labeled “a” and the red line is not labeled “b” .
PS: Overview · Plots writes “if label is empty”…what is empty?
how does one label two lines?
using Plots; pyplot()
plot(Plots.fakedata(50,2), w=3, labels=[ "a", "b" ])
the blue line is not labeled “a” and the red line is not labeled “b” .
PS: Overview · Plots writes “if label is empty”…what is empty?
This is the #1 most asked question on Plots. The answer is that columns are series - so you should use a row matrix. label = ["a" "b"]
.
There’s an open issue to change the behaviour to accept a Vector.
For anyone else landing here 5+ years later, it seems Plots.jl has settled on not letting you pass in a Vector of labels. It must be a row vector as shown above.
Warning: What follows is guidance from a julia novice. If you have labels=["a","b"]
of type Vector{String}
, then I think the cleanest way to pass it in all at once is
t = 1:100
y = rand(Float64, (100,3))
labels = ["a","b","c"]
plot(t, y, labels = hcat(labels...))
Probably the best method overall is to call plot
for each series and set that individual label like this:
t = 1:100
y = rand(Float64, (100,3))
labels = ["a","b","c"]
pl = plot()
for i in axes(y, 2)
plot!(pl,t,y[:,i], label=labels[i])
end
display(pl)
I usually do
labels = ["a","b","c"]
plot(t, y, labels = permutedims(labels))