# Number of digits in xticks for Plots.jl

**URL:** <https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533>\
**Category:** General Usage\
**Created:** [September 4, 2018, 12:19pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533 "2018-09-04T12:19:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [September 4, 2018, 12:19pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533/1 "2018-09-04T12:19:48Z")

</div>

Hi all-

I have a crowding issue on the scale of my x-axis because too many digits are displayed. I tried to round the values I pass to xticks, but that did not help. Is there any way to control the number of digits that are display?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 4, 2018, 12:31pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533/2 "2018-09-04T12:31:16Z")

</div>

What command are you currently using to plot? `xticks` can [take a range with a step](http://docs.juliaplots.org/latest/attributes/#axis-and-xaxisyaxiszaxis), like this: `1:2:10` which will return ticks at these locations:

```julia
julia> collect(1:2:10)
5-element Array{Int64,1}:
 1
 3
 5
 7
 9

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [September 4, 2018, 2:12pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533/3 "2018-09-04T14:12:11Z")

</div>

I am passing a step range like this: round.(range(…),digits =2). I am having trouble reproducing the problem with a minimum working example. It must depend on some combination of factors that I do not fully understand.

This works:

```julia
using Plots,Distributions
Parms = [[100.0,15.0],[0.0,.005],[10.0,5.0],[10,.01]]
p = plot(layout=4)
for (i,parms) in enumerate(Parms)
    x = rand(Normal(parms...),100)
    y = rand(Normal(parms...),100)
    lb = minimum(x); ub = maximum(x)
    ticks = round.(range(lb,stop=ub,length = 4),digits=2)
    scatter!(p,x,y,subplot=i,xticks=ticks)
end
display(p)

```

But as you can see from my more complicated example, sometimes it does not work. I was able to work around this particular problem by changing the size of the plot. I will repost if I can reproduce with something that I can share.

 ![Example](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f02250fcc9c609eb494c7874d11135f30b3d6ec.png)

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [September 4, 2018, 2:14pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533/4 "2018-09-04T14:14:24Z")

</div>

I just want to clarify that my example is basically the same except that I am using simulated data.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 4, 2018, 2:21pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533/5 "2018-09-04T14:21:31Z")

</div>

Ah, are you talking about the example in the upper right? You can reduce the fontsize for the axis labels (using e.g. `xtickfont = font(20, "Courier")`). I’m not quite sure, but I think there was an option to rotate the tick labeling too, but I can’t recall how its called right now.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [September 4, 2018, 2:27pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533/6 "2018-09-04T14:27:14Z")

</div>

The upper left and lower right subplots are problematic because they should have two decimals. The upper right is overcrowded, but conforms to the intended configuration. I guess this isn’t a general problem, but hopefully I can identify the parameters that produce it.

Thanks for the ideas nonetheless.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 20, 2019, 2:25pm UTC](https://discourse.julialang.org/t/number-of-digits-in-xticks-for-plots-jl/14533/7 "2019-12-20T14:25:23Z")

</div>

You can convert the ticks to strings with the format you want using Printf and then use the strings as tick labels. For example:

```julia
using Plots, Printf
x = rand(10); y = rand(10);
ticks = collect(0:0.2:1)
ticklabels = [@sprintf("%5.1f",x) for x in ticks]
plot(x,y)
plot!(xticks=(ticks,ticklabels))

```

which will give you the number of decimal places defined by printf
