# More ticks in \`Plots.jl\`

**URL:** <https://discourse.julialang.org/t/more-ticks-in-plots-jl/5575>\
**Category:** Visualization\
**Tags:** question\
**Created:** [August 26, 2017, 1:06pm UTC](https://discourse.julialang.org/t/more-ticks-in-plots-jl/5575 "2017-08-26T13:06:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 26, 2017, 1:06pm UTC](https://discourse.julialang.org/t/more-ticks-in-plots-jl/5575/1 "2017-08-26T13:06:04Z")

</div>

Sometimes `Plots.jl` gives me too few ticks with some backends, especially GR, which is now my favourite. MWE:

```julia
using Plots
using StatPlots
gr() # important
x = linspace(0.2291313228541989, 0.3318750511155737, 100)
plot(density(x)) # 1 or 2 ticks

```

I looked at the source for something like R’s `pretty`, and came up with this solution:

```julia
plt = plot(density(x); xticks = optimize_ticks(extrema(x)...; k_min = 10)[1])

```

which works, but is there anything simpler? In particular, being able to pass `k_min` as an argument without saving `x` and computing its extrema would be convenient.

_edit_: I forgot to mention that I wish to avoid specifying ticks manually. I just want more of them, but otherwise automated.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 26, 2017, 1:36pm UTC](https://discourse.julialang.org/t/more-ticks-in-plots-jl/5575/2 "2017-08-26T13:36:02Z")

</div>

It actually sounds like a bug: from [here](https://github.com/JuliaPlots/Plots.jl/blob/56bda82529676d15be417b7d92703964ce0ec2f8/src/axes.jl#L184) it would seem that the intended tick number, if the user doesn’t provide anything, is between 5 and 8 (but I agree that ideally those variable should be possible to give as a keyword argument). If you open an issue I can look into that.

On a separate note, you shouldn’t need to import both `Plots` at `StatPlots` (at least on master, it was fixed recently) and `density(x)` should be sufficient to also draw the plot.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 26, 2017, 1:47pm UTC](https://discourse.julialang.org/t/more-ticks-in-plots-jl/5575/3 "2017-08-26T13:47:42Z")

</div>

Thanks, opened an issue:  
[https://github.com/JuliaPlots/Plots.jl/issues/1045](https://github.com/JuliaPlots/Plots.jl/issues/1045)

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 26, 2017, 1:49pm UTC](https://discourse.julialang.org/t/more-ticks-in-plots-jl/5575/4 "2017-08-26T13:49:53Z")

</div>

Thanks for opening the issue! Definitely something funky with the `optimize_ticks` function:

```julia
julia> optimize_ticks(2.29,3.3; k_min = 5, k_max = 8)
([3.0], 2.29, 3.3)

julia> optimize_ticks(2.3,3.3; k_min = 5, k_max = 8)
([2.4, 2.6, 2.8, 3.0, 3.2], 2.3, 3.3)

julia> optimize_ticks(2.29,3.3; k_min = 5, k_max = 8, strict_span = false)
([2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4], 2.2, 3.4000000000000004)

julia> optimize_ticks(2.3,3.3; k_min = 5, k_max = 8, strict_span = false)
([2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4], 2.2, 3.4000000000000004)

```

the `strict_span = true` default seems to be the issue, I’ll see if I find a reliable solution.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 29, 2017, 11:01am UTC](https://discourse.julialang.org/t/more-ticks-in-plots-jl/5575/5 "2017-08-29T11:01:01Z")

</div>

Should be fixed in Plots and PlotUtils master, now tick number is between 4 and 8:

![29784472-f58db5c2-8c1b-11e7-8094-7b9d3b48e151](https://global.discourse-cdn.com/julialang/original/3X/0/1/01c29f2d099e596f4f43e0525a0ef45c1d963bbb.png)
