# Adjust the decimals in scientific notation with Plots.jl

**URL:** <https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555>\
**Category:** New to Julia\
**Tags:** plots, formatting\
**Created:** [August 12, 2025, 10:05am UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555 "2025-08-12T10:05:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kraqbi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kraqbi/32/206682_2.png) [@kraqbi](https://discourse.julialang.org/u/kraqbi)\
**Post date:** [August 12, 2025, 10:05am UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/1 "2025-08-12T10:05:52Z")

</div>

Hello!  
I try to publish my figures so I need to edit them as nicely as possible.  
I have trouble adjusting the format of my ylabel.

I would like to keep a scientific notation, but Plots.jl is automatically set to a two digits precision.  
I would like to keep it to one (else, it takes too much place in subplots).

For example :

```julia-auto
using Plots
x = 0:1:10
plot(x, x*1e-6)

```

How can I keep the ylabel with a format like 2.5x10^-6 instead of 2.50x10^-6 ?

I guess I should use yformatter, but I could not find a documentation or a tutorial to apply.  
(I also take recommendations of backends for publication-grade figures)  
Thanks!

---

<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:** [August 12, 2025, 10:39am UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/2 "2025-08-12T10:39:31Z")

</div>

> [@kraqbi](#):
>
> I guess I should use yformatter, but I could not find a documentation or a tutorial to apply.

There are some examples here in discourse. See if [this](https://discourse.julialang.org/t/argument-for-number-of-axis-ticks/76817/2) one helps.

With the latest recommended Format.jl package, try:

```julia-auto
using Format, Plots
x = 0:1:10
plot(x, x*1e-6, yformatter = x -> cfmt( "%.1e", x), tickfontsize=6)

```

---

<div class="post-metadata">

**Author:** ![kraqbi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kraqbi/32/206682_2.png) [@kraqbi](https://discourse.julialang.org/u/kraqbi)\
**Post date:** [August 12, 2025, 11:32am UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/3 "2025-08-12T11:32:24Z")

</div>

```julia-auto
1 dependency successfully precompiled in 1 seconds. 537 already precompiled.
  1 dependency had output during precompilation:
┌ Formatting
│ ┌ Warning: DEPRECATION NOTICE
│ │ 
│ │ Formatting.jl has been unmaintained for a while, with some serious
│ │ correctness bugs compromising the original purpose of the package. As a result,
│ │ it has been deprecated - consider using an alternative, such as
│ │ `Format.jl` (https://github.com/JuliaString/Format.jl) or the `Printf` stdlib directly.
│ │ 
│ │ If you are not using Formatting.jl as a direct dependency, please consider
│ │ opening an issue on any packages you are using that do use it as a dependency.
│ │ From Julia 1.9 onwards, you can query `]why Formatting` to figure out which
│ │ package originally brings it in as a dependency.
│ └ @ Formatting ~/.julia/packages/Formatting/3VxOt/src/Formatting.jl:12
└  

```

I will try to see what Format.jl can do…

---

<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:** [August 12, 2025, 11:32am UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/4 "2025-08-12T11:32:47Z")

</div>

Please refer to the example I have added above.

---

<div class="post-metadata">

**Author:** ![kraqbi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kraqbi/32/206682_2.png) [@kraqbi](https://discourse.julialang.org/u/kraqbi)\
**Post date:** [August 12, 2025, 11:36am UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/5 "2025-08-12T11:36:07Z")

</div>

I would prefer a notation with x10^n if it is not too hard.

---

<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:** [August 12, 2025, 11:46am UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/6 "2025-08-12T11:46:41Z")

</div>

> [@kraqbi](#):
>
> I would prefer a notation with x10^n if it is not too hard

I don’t know of an easy way, but the following is within reach, with some more labour:

```julia-auto
using Plots

x = 0:1:10
p = plot(x, x*1e-6, yformatter=:scientific)
yt = yticks(p)
# Edit yt programmatically (done here manually):
yt[1][2] .= ["0", "2.5×10^{−6}", "5.0×10^{−6}", "7.5×10^{−6}", "1.0×10^{−5}"]

plot!(p, yticks=yt[1], tickfontsize=6)

```

With a bit more work below.

> **CODE: to programmatically edit scientific plot ticks**
>
> ```julia-auto
> using Format, Plots
> 
> function sci_ticks(yt; precision=1)
> # "×" can be typed by \times<tab>
> vs = [String.(split(y,'×')) for y in yt[1][2]]
> ix = findall(x->length(x)==1, vs)
> for i in eachindex(vs)
> i ∈ ix ? (vs[i] = [vs[i][1], ""]) : (vs[i][2] = "×" * vs[i][2])
> end
> ystr = format.(parse.(Float64, first.(vs)), precision=precision)
> yt[1][2] .= ystr .* last.(vs)
> return yt[1]
> end
> 
> x = 0:1:10
> p = plot(x, x*1e-6, yformatter=:scientific)
> plot!(p, yticks=sci_ticks(yticks(p); precision=1), tickfontsize=6)
> 
> ```

---

<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:** [August 12, 2025, 5:33pm UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/7 "2025-08-12T17:33:48Z")

</div>

Actually, there is a simple way to handle your example:

```julia-auto
plot(x, x*1e-6, yformatter=x->round(x,sigdigits=1))

```

---

<div class="post-metadata">

**Author:** ![kraqbi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kraqbi/32/206682_2.png) [@kraqbi](https://discourse.julialang.org/u/kraqbi)\
**Post date:** [August 13, 2025, 12:12pm UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/8 "2025-08-13T12:12:35Z")

</div>

First, thank you very much for all your answers.  
It is not clear to me if yformatter does format only the yticks or the values themselves.  
Anyhow, with your new solution, I cannot for example have the value with no digits  
(like 2x10^-6 instead of 2.0x10^-6).  
(I tried that : )  
`plot(x, x*1e-6, yformatter=x->round(x,sigdigits=0))`

---

<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:** [August 13, 2025, 3:24pm UTC](https://discourse.julialang.org/t/adjust-the-decimals-in-scientific-notation-with-plots-jl/131555/9 "2025-08-13T15:24:10Z")

</div>

Indeed, this simple approach doesn’t seem to work when asking for zero digits for numbers \< 1.

Another alternative using Printf.jl:

```julia-auto
using Printf
plot(x, x*1e-6, yformatter=x->join(split(@sprintf("%.0e", x), 'e'), "×10^{") * "}")

```
