1

I hate those (semi/log-)log plots with: 10^⁻1, 10⁰ and 10¹ labels.

A good way to change only these by, simply: 0.1, 1, and 10 please?

plot(x, y, yscale=:log10, label="", yformatter = yi -> yi==0.1 ? "0.1" : yi==1 ? "1" : yi==10 ? "10" : yi)

does part of the job, but how to keep the default 10^p format for |p|>1, please?

1 Answers1

0

You could write something like:

function yformatter(yi)
    yi < 1.0 && return string(yi)
    yi <= 10 && return string(round(Int,yi))
    nums = [['¹','²','³'] ; '⁴':'⁹']
    return "10$(nums[round(Int,log10(yi))])"
end

And now you have:

julia> yformatter.([0.1, 1, 10, 100, 1_000, 10_000, 100_000])
7-element Vector{String}:
 "0.1"
 "1"
 "10"
 "10²"
 "10³"
 "10⁴"
 "10⁵"
Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • Thank you! but how one should use your yformatter function inside a simple script like e.g., (a) x=-2:0.25:2 (b) y = @. 10^x and finally (c) plot(x, y, yscale=:log10, label="") please? – Frédéric Paletou Feb 08 '23 at 16:46
  • plot(x, y, yscale=:log10, label="", yformatter = yi -> yformatter.(yi) ) seems ok, although this yformatter function/solution doesn't keep the initial 10^p format for p<=-2. – Frédéric Paletou Feb 08 '23 at 17:05
  • I guess you now can easily update it for other cases. I guess `plot(x, y, yscale=:log10, label="", yformatter = yformatter)` should work too. – Przemyslaw Szufel Feb 08 '23 at 17:19