# Strange behavior using Plots / array initialization

**URL:** <https://discourse.julialang.org/t/strange-behavior-using-plots-array-initialization/17045>\
**Category:** New to Julia\
**Created:** [November 1, 2018, 10:05am UTC](https://discourse.julialang.org/t/strange-behavior-using-plots-array-initialization/17045 "2018-11-01T10:05:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ceysa75](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ceysa75/32/19121_2.png) [@ceysa75](https://discourse.julialang.org/u/ceysa75)\
**Post date:** [November 1, 2018, 10:05am UTC](https://discourse.julialang.org/t/strange-behavior-using-plots-array-initialization/17045/1 "2018-11-01T10:05:54Z")

</div>

Dear all,

I just want to share a strange behavior which I hope you can reproduce (IJulia environment, Julia 1.0.1). Please find below my code which most of the time leads to a correct plot. But if you run the code repeatedly it ends up plotting something weird or even with an error (ArgumentError: At least one finite value must be provided to formatter).

But this only happens if I define an uninitialized array. If I define a zero filled array, all is fine . Thanks for your help…

```julia
using Plots
dt = 1.0/100.0
Fz = Array{Float64}(undef, 50)
t = Array{Float64}(undef, 50)
#Fz = zeros(Float64, 50)
#t = zeros(Float64, 50)

for i = 1:length(Fz)
    t[i] = (i-1)*dt    
    Fz[i] = Fz[i]+sin(pi*fs*t[i])    
end

plot(t,Fz)

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 1, 2018, 2:30pm UTC](https://discourse.julialang.org/t/strange-behavior-using-plots-array-initialization/17045/2 "2018-11-01T14:30:20Z")

</div>

The `Array{Float64}(undef, 50)` is extra awkward to make it clear, that the content get’s filled with undefined numbers.  
Did you try at all to actually inspect `t` `Fz` before plotting?

Since you access Fz in `Fz[i] = Fz[i]+sin(pi*fs*t[i])` before assigning it a value, you can get any number there is. E.g. if it’s all NaNs, you’ll get an array full of NaNs!

---

<div class="post-metadata">

**Author:** ![ceysa75](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ceysa75/32/19121_2.png) [@ceysa75](https://discourse.julialang.org/u/ceysa75)\
**Post date:** [November 1, 2018, 3:58pm UTC](https://discourse.julialang.org/t/strange-behavior-using-plots-array-initialization/17045/3 "2018-11-01T15:58:21Z")

</div>

Ok, got that. I understand and also see it now. Thanks
