# Colour plot points based on another vector

**URL:** <https://discourse.julialang.org/t/colour-plot-points-based-on-another-vector/59776>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [April 22, 2021, 4:35am UTC](https://discourse.julialang.org/t/colour-plot-points-based-on-another-vector/59776 "2021-04-22T04:35:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [April 22, 2021, 4:35am UTC](https://discourse.julialang.org/t/colour-plot-points-based-on-another-vector/59776/1 "2021-04-22T04:35:27Z")

</div>

Hi everyone,

I am trying to amend the example given here: [https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956](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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 22, 2021, 7:10am UTC](https://discourse.julialang.org/t/colour-plot-points-based-on-another-vector/59776/2 "2021-04-22T07:10:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [April 22, 2021, 7:38am UTC](https://discourse.julialang.org/t/colour-plot-points-based-on-another-vector/59776/3 "2021-04-22T07:38:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 22, 2021, 7:56am UTC](https://discourse.julialang.org/t/colour-plot-points-based-on-another-vector/59776/4 "2021-04-22T07:56:57Z")

</div>

> [@SDA](#):
>
> `C = c_idx.*([A[nn]./A[nn] for nn=1:length(A)])`

_ **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))`
