# Plotting points on a plot with subplots

**URL:** <https://discourse.julialang.org/t/plotting-points-on-a-plot-with-subplots/100993>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [June 29, 2023, 7:53pm UTC](https://discourse.julialang.org/t/plotting-points-on-a-plot-with-subplots/100993 "2023-06-29T19:53:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maoc](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@maoc](https://discourse.julialang.org/u/maoc)\
**Post date:** [June 29, 2023, 7:53pm UTC](https://discourse.julialang.org/t/plotting-points-on-a-plot-with-subplots/100993/1 "2023-06-29T19:53:27Z")

</div>

I have a rather long time series. For example, T = mx100. I can break this long series into m subplots. For example:

```julia
using Plots

# number of supblots
m=5

# Size of my time series
T = m*100

# Time
t_ = 1:T
t_ = reshape( t_ , 100,m)

# X time series
X = rand(Normal(0,1), T)
X = reshape( X, 100,m)

# Plot
plot(t_, X, fmt=:png , layout = (m,1))

```

I have a vector U of size T of many zeros and few ones. For example:

```julia
# Points
U = rand(Binomial(1,.3) , T )
U = [1:T U]

```

I want to add to the previous plot, points just on the time axis where the 1’s in the U vector happen. If for example I had two ones at position 25 and 75, I can do this (here m=5) :

```julia
# Plot
plot(t_, X, fmt=:png , layout = (m,1), legend = false)
scatter!([25, 75], [0 , 0],color=:red, markersize=4)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/5/f/5f4c0b2b1ee33cd379e36325b4af442fb453db4d.png)  
Unfortunately, I cannot generalize to the general U case.  
help!

---

<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:** [June 30, 2023, 2:25pm UTC](https://discourse.julialang.org/t/plotting-points-on-a-plot-with-subplots/100993/2 "2023-06-30T14:25:50Z")

</div>

A simple solution using the same approach, is to convert the `0`s to `NaN`, so as to ignore them in `scatter()`:

```julia
U = rand(Binomial(1,.3) , T);
U2_ = convert.(Float64, U);
U2_ = reshape(U2_, 100, m);
U2_[U2_ .== 0] .= NaN;
scatter!(t_, U2_, c=:red, ms=4)

```
