Plot step function [x+1/2]

Yes scatter needs arrays, so the usual way to write this would be scatter([x], [y]).

For a plot to be shown it has to be the return value of the last evaluated expression. As loops in Julia return nothing, you need to either explicitly create a plot object and call it like this

p = plot()

for x ∈ 2:length(x)-1
    plot!(...)
    scatter!(...)
end
 
p

or add a call to current() to your code, which will just display the last plot object you’ve plotted to.

1 Like