Basically I want to adjust the number of the significant digits in the numeric labels on the x axis:
using Plots
using StrFormat
x = 0:1e5:8e6
y = rand(Float64, length(x))
plot(x,y) # -> 2.0 × 10^6
plot(x,y; xformatter=(x -> f"\%.0e(x)")) # -> 2e+06
By default, the plot
command plots beautiful numeric labels often with one extra 0 than necessary; for example, “2.0”, “4.0”, “6.0”, . . . I want them to be “2”, “4”, “6”, . . .
- Is there a Plot attribute for that? I haven’t found one.
- What’s the default
xformatter
? If it can be used by the user and if there is an adjustable parameter to it, the user can write something likexformatter=(x -> defaultformatter(x, precision=1))
? - Is there a string formatter that produces labels like “2 × 10^6” with a “real” superscript “6” ? (One can write such a function that produces a LaTeX string but that would be re-inventing a poorer wheel.)
Apart from this question, I’d like to get hold of the default formatter anyway because that would be useful with annotate!()
.