# Unevenly spaced x in a plot (automatic plotting of functions)

**URL:** <https://discourse.julialang.org/t/unevenly-spaced-x-in-a-plot-automatic-plotting-of-functions/93903>\
**Category:** New to Julia\
**Tags:** plotting, plots\
**Created:** [February 2, 2023, 1:36am UTC](https://discourse.julialang.org/t/unevenly-spaced-x-in-a-plot-automatic-plotting-of-functions/93903 "2023-02-02T01:36:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nari/32/46452_2.png) [@nari](https://discourse.julialang.org/u/nari)\
**Post date:** [February 2, 2023, 1:36am UTC](https://discourse.julialang.org/t/unevenly-spaced-x-in-a-plot-automatic-plotting-of-functions/93903/1 "2023-02-02T01:36:41Z")

</div>

I recently learned that I can plot a function f(x) as follows.

```julia
using Plots
f(x) = 1/(1+exp(-x))
scatter(f, (-10.0,10.0)...)

```

And, I noticed that the plot is not evenly spaced with respect to the x-axis when plotted with a scatter as shown in the figure. There are more points clustered where the curve is steeper and fewer points where it is less varied. There seems to be some kind of mathematical intelligence behind it.

![f](https://global.discourse-cdn.com/julialang/original/3X/d/1/d146334bd0f026dfa77b410a8c3aad8662a30d4b.png)

How are the x coordinates of each of these points being generated?  
Is there a function that returns such an unevenly spaced x coordinates when given f(x)?

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [February 2, 2023, 2:15am UTC](https://discourse.julialang.org/t/unevenly-spaced-x-in-a-plot-automatic-plotting-of-functions/93903/2 "2023-02-02T02:15:32Z")

</div>

Your code doesn’t run for me (julia 1.8.5).  
Maybe you left some lines out…  
What packages are you using?

---

<div class="post-metadata">

**Author:** ![nari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nari/32/46452_2.png) [@nari](https://discourse.julialang.org/u/nari)\
**Post date:** [February 2, 2023, 3:33am UTC](https://discourse.julialang.org/t/unevenly-spaced-x-in-a-plot-automatic-plotting-of-functions/93903/3 "2023-02-02T03:33:46Z")

</div>

Oh, I used `Plots` v1.38.3 with `GR` backend on Julia v.1.8.5. I updated the code.

---

<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:** [February 2, 2023, 8:04am UTC](https://discourse.julialang.org/t/unevenly-spaced-x-in-a-plot-automatic-plotting-of-functions/93903/4 "2023-02-02T08:04:02Z")

</div>

Check this relevant [Plots.jl’s issue](https://github.com/JuliaPlots/Plots.jl/issues/621), from which we can learn that the code is in file `adapted_grid.jl`. It seems to be using the curvature (second derivative).

---

<div class="post-metadata">

**Author:** ![nari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nari/32/46452_2.png) [@nari](https://discourse.julialang.org/u/nari)\
**Post date:** [February 2, 2023, 8:57am UTC](https://discourse.julialang.org/t/unevenly-spaced-x-in-a-plot-automatic-plotting-of-functions/93903/5 "2023-02-02T08:57:25Z")

</div>

Thank you for your comment and link. This helps me a lot!
