Adjust the decimals in scientific notation with Plots.jl

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

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
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)
1 Like