Adding Plotly Traces to an Array

You can pre-allocate a vector of traces:

nr_of_traces = size(data, 2)
traces = Vector{GenericTrace}(undef, nr_of_traces)
for idx in 1:nr_of_traces
    traces[idx] = scatter(x=r_range,  y=data[:,idx],
                        mode="lines",
                        name = "$idx")
end

If you don’t know in advance how many traces will be needed, start with

traces = GenericTrace[]

then push!(traces, scatter(...))

4 Likes