Colour plot points based on another vector

Hi everyone,

I am trying to amend the example given here: https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956, which plots a vector of arrays.

The example I am working with is a 3D plot but hopefully the 2D scenario is sufficient for a MWE. I want the plotted points to be coloured based on their location on an attractor, which is indicated by c_idx:

using Plots
a1 = [1 , 2 , 3]
a2 = [1,2]
a3 = [3,1]
A = [a1,a2,a3]
X = [ i*ones(length(a)) for (i,a) in pairs(A)]

#### this is the new bit...
c_idx = [2, 7, -1]
C = c_idx.*([A[nn]./A[nn] for nn=1:length(A)])
###

scatter(X, A, c=:RdBu, marker_z=C, ms=6, legend =:false)

I have essentially tried to do ones(size(A)) and scale this based on the colour index I want. In a really dumb way but I haven’t yet worked out how to find the size of a vector of arrays. Unfortunately, the colour is ignored when I do it in the way shown above.

Any ideas will be greatly appreciated!

If you transpose C, does it produce what you want?
scatter(X, A, c=:RdBu, marker_z=C', ms=6, legend =:false)

1 Like

Ugh! So simple! I had thought C and X should have the same dimension. Thank you very much for your help Rafael :smiley:

1 Like

NB: on another note, one may write the above more compactly as follows:
C = c_idx.*ones.(size.(A))
or:
@. C = c_idx*ones(size(A))

1 Like