Hi commuinty,
Q1: Is there a way to use x, y and legend (as below) to plot data in series?
#y matrix: row corresponding to each x value, column for each series (marked by legend) of data
x=[2 4 6 8 10 12]#corresponding to each row
y= [10.6667 10.3333 8.0 14.6667;
10.0 7.33333 7.66667 17.0;
8.0 7.33333 8.33333 12.0;
4.33333 5.33333 7.33333 11.3333;
4.66667 4.0 4.0 10.6667;
4.33333 3.33333 4.0 12.0]
legend=["a" "b" "c" "d"] #each series-column
using Plots
#expected points distribution as like:
plot(y,legend) #but x and legend not accordingly specified
#trial1:
for i in 1:4 #for 4 series
if i==1
plot(x,y[:,i],label=legend[i])
else
plot!(x,y[:,i],label=legend[i])
end
end #not generating any graph
According to
http://docs.juliaplots.org/latest/examples/gr/#functions-adding-data-and-animations
#trial2
for i in 1:4 #for 4 series
if i==1
p=plot(x,y[:,i],label=legend[i])
else
push!(p,x,y[:,i])#,label=legend[i] #not work probably as not animation?
end
end
Q2: Also, within a for loop, scatter(,label=legend[i]) tend to replicate the mark of i-th legend the number of row times. This post was discussing about the same problem, but the suggested commands to avoid replication seems not compiled, while the one for animation (in trial2) doesn’t work as well.