# Plotting multiple points at every instance

**URL:** <https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [April 5, 2019, 7:30pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814 "2019-04-05T19:30:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ennvvy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ennvvy/32/7816_2.png) [@ennvvy](https://discourse.julialang.org/u/ennvvy)\
**Post date:** [April 5, 2019, 7:30pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814/1 "2019-04-05T19:30:51Z")

</div>

I am trying to plot the results of my Monte-Carlo simulation. I have data of the following form, where each row corresponds to a one-time instance.

```julia
b1
500-element Array{Array{Float64,1},1}:
 [115.0]       
 [112.0, 113.0]
 [112.0]       
 [104.0]       
 [111.0]       
 [112.0]       
 ⋮             
 [116.0]       
 [100.0]       
 [106.0]       
 [107.0, 108.0]

```

When I do `scatter(1:1:500,b1)`, I get the following error

> attempt to access 1-element Array{Float64,1} at index [2]

What is a good way to fix this?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [April 6, 2019, 12:00pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814/2 "2019-04-06T12:00:03Z")

</div>

You need b1 to be a vector of numbers. The easiest way of doing that is `reduce(vcat, b1)`

---

<div class="post-metadata">

**Author:** ![ennvvy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ennvvy/32/7816_2.png) [@ennvvy](https://discourse.julialang.org/u/ennvvy)\
**Post date:** [April 6, 2019, 12:02pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814/3 "2019-04-06T12:02:18Z")

</div>

If I did that, I get an array of numbers and would loose pertinent information at a particular time instant. For example, b[2]=[1,2] would just become entries in the array. I want the plot to convey that at t=2, there are two values.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 6, 2019, 1:56pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814/4 "2019-04-06T13:56:09Z")

</div>

You need to duplicate the time information so that you have (x, y) pairs with the same number of xs and ys.

---

<div class="post-metadata">

**Author:** ![ennvvy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ennvvy/32/7816_2.png) [@ennvvy](https://discourse.julialang.org/u/ennvvy)\
**Post date:** [April 6, 2019, 1:57pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814/5 "2019-04-06T13:57:00Z")

</div>

But to flatten the nested array is turning out to be hard for me.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 6, 2019, 2:30pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814/6 "2019-04-06T14:30:26Z")

</div>

E.g.

```julia
julia> t = [1, 2]
2-element Array{Int64,1}:
 1
 2

julia> b = [[3], [4, 5] ]
2-element Array{Array{Int64,1},1}:
 [3]
 [4, 5]

julia> collect(Iterators.flatten([[ (tt, x) for x in bb] for (tt, bb) in zip(t, b) ]))
3-element Array{Tuple{Int64,Int64},1}:
 (1, 3)
 (2, 4)
 (2, 5)

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 6, 2019, 2:30pm UTC](https://discourse.julialang.org/t/plotting-multiple-points-at-every-instance/22814/7 "2019-04-06T14:30:53Z")

</div>

But it’s easier just to spit out the information in this format when you first create the data.
