# Plot a vector of Arrays

**URL:** <https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [February 9, 2021, 10:03pm UTC](https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956 "2021-02-09T22:03:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fms-1988](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fms-1988/32/20275_2.png) [@fms-1988](https://discourse.julialang.org/u/fms-1988)\
**Post date:** [February 9, 2021, 10:03pm UTC](https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956/1 "2021-02-09T22:03:44Z")

</div>

I want to plot a vector. But the elements of this vector are arrays.  
Was there any way to plot the data that way?

```julia
a1 = [1 , 2 , 3]
a2 = [1,2]
a3 = [3,1]
A = [a1,a2,a3]
A = convert(Array{Any}, A)
n = 1:3

using Plots
scatter(n,A)

```

 ![SmartSelect_20210209-195605_Squid](https://global.discourse-cdn.com/julialang/original/3X/3/0/30cf02ed996f2a62d74643565bf0ad0fc3201c0a.jpeg)

---

<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:** [February 9, 2021, 10:43pm UTC](https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956/2 "2021-02-09T22:43:09Z")

</div>

One possibility:

```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)]
scatter(X, A, ms=6, legend =:false)

```

![scatter_array_plot](https://global.discourse-cdn.com/julialang/original/3X/7/d/7d3deb99cb19756b6f2675665c41d98c57b45d82.png)

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [February 10, 2021, 1:36am UTC](https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956/3 "2021-02-10T01:36:52Z")

</div>

> [@rafael.guerra](#):
>
> ```julia
> X = [i*ones(length(A[i,:]...)) for i in 1:length(A)]
> 
> ```

I think you can replace `length(A[i,:]...)` with just `length(A[i])`, no?

* * *

EDIT: FWIW, I would have probably done it this way 🙂

```julia
X = [i*ones(length(a)) for (i,a) in enumerate(A)]

```

---

<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:** [February 10, 2021, 5:59am UTC](https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956/4 "2021-02-10T05:59:02Z")

</div>

@briochemc, much cleaner. Nicer code also with pairs (Julia is really great):  
`X = [i*ones(length(a)) for (i,a) in pairs(A)]`  
_PS: edited the code above._

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [February 10, 2021, 7:00am UTC](https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956/5 "2021-02-10T07:00:09Z")

</div>

Oh great, I didn’t know about that use of `pairs`! I’m glad I chimed in here just to learn about this! Thanks!

---

<div class="post-metadata">

**Author:** ![fms-1988](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fms-1988/32/20275_2.png) [@fms-1988](https://discourse.julialang.org/u/fms-1988)\
**Post date:** [February 10, 2021, 10:02am UTC](https://discourse.julialang.org/t/plot-a-vector-of-arrays/54956/6 "2021-02-10T10:02:13Z")

</div>

Thank you @rafael.guerra and @briochemc .  
Very understandable codes.
