Plot a vector of Arrays

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

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)

1 Like

One possibility:

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

5 Likes

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


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

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

@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.

2 Likes

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

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