# Control over sampling when plotting functions

**URL:** <https://discourse.julialang.org/t/control-over-sampling-when-plotting-functions/62565>\
**Category:** Visualization\
**Created:** [June 8, 2021, 8:45am UTC](https://discourse.julialang.org/t/control-over-sampling-when-plotting-functions/62565 "2021-06-08T08:45:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [June 8, 2021, 8:45am UTC](https://discourse.julialang.org/t/control-over-sampling-when-plotting-functions/62565/1 "2021-06-08T08:45:55Z")

</div>

Plotting functions in Julia is quite easy and works super nice for smooth functions. However, for more complex functions (switched), some points get lost.

```julia
f(x) = 0.6 > mod(x,1) > 0.5 ? 1 : 0
plot(f, xlims=(0,10))

```

 ![repetitive](https://global.discourse-cdn.com/julialang/original/3X/e/b/eb6e34ddd561a845a3001854fcc693b7b9ca25c0.png)

Is there an easy way to control the sampling of the function without having to explicitly generate the `x` and `f(x)` vectors?

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 8, 2021, 9:03am UTC](https://discourse.julialang.org/t/control-over-sampling-when-plotting-functions/62565/2 "2021-06-08T09:03:28Z")

</div>

There is `plot(f:: Function, x::AbstractVector)` which solves half of your question. What kind of control do you want?

---

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [June 8, 2021, 10:15am UTC](https://discourse.julialang.org/t/control-over-sampling-when-plotting-functions/62565/3 "2021-06-08T10:15:26Z")

</div>

Thanks, that answers my question. Looking through the docs is hard. These work good:

```julia
plot(f, 0:0.001:3)
plot(f, range(0, stop=3, step=0.001))

```
