# How to Plot Step Functions \[x\] Correctly in Julia?

**URL:** <https://discourse.julialang.org/t/how-to-plot-step-functions-x-correctly-in-julia/84087>\
**Category:** General Usage\
**Tags:** plots\
**Created:** [July 12, 2022, 7:05am UTC](https://discourse.julialang.org/t/how-to-plot-step-functions-x-correctly-in-julia/84087 "2022-07-12T07:05:50Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [July 12, 2022, 10:10am UTC](https://discourse.julialang.org/t/how-to-plot-step-functions-x-correctly-in-julia/84087/5 "2022-07-12T10:10:13Z")

</div>

Here is a version without the plot loop using `NaN` at the breaks:

```julia
using Plots; gr()

x = -12:12
xp = [[i, i+1 - 5*eps(), NaN] for i in x[1:end-1]]
xx = collect(Iterators.flatten(xp))
yy = floor.(xx)
plot(xx, yy, c=:black, label=false, framestyle = :origin)
scatter!(xx', yy', msc=:black, mc=[:black :white :white], ms=3)

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-plot-step-functions-x-correctly-in-julia/84087)._
