I have the feeling that this problem has already been solved, but I haven’t been able to locate the solution.
Basically, I want all numeric labels and letterings for negative numbers to use the unicode minus symbol, not the ASCII hyphen character. I imagine that there is a simple global switch or a simple switch to the number formatter . . . But, as in the discussion I link at the end of this message, it seems that you are supposed to write your own number formatter and probably I would be able to achieve my goal by doing so. (If that’s the only way, I would like to know how to write a smart formatter that can handle various cases like “1.0 x 10^{-n}”. A much simpler way would be to get hold of the result of Makie
’s native formatter and replace the hyphen symbols, if any, with minus symbols.)
For visualization, the minus symbol, if available, is almost always the better choice than the hyphen. I guess Makie
defaults to the hyphen only for backward compatibility or to be conservative considering that some fonts cover only a very limit set of characters.
Here is a little toy program to demonstrate that Makie
uses the hyphen whereas Plots.jl
uses the minus symbols:
using CairoMakie
using Plots
xs = -π:(π/16):π
vals = cos.(xs)
minus2 = "−2"
hyphen2 = "-2"
let fig = Figure(; fontsize = 28) # font="Lucida Grande"
ax = Axis(fig[1,1])
lines!(ax, xs, vals)
text!(fig.scene, Point3f(0.25,0.12, 0); text = minus2, color=:red,
space=:relative)
text!(fig.scene, Point3f(0.25,0.08, 0); text = hyphen2, color=:blue,
space=:relative)
save("tmp-Makie.png", fig)
end
let p = Plots.plot(xs, vals)
annotate!(p, -2, -0.85, Plots.text(minus2, :red, 10))
annotate!(p, -2, -0.95, Plots.text(hyphen2, :blue,10))
savefig(p, "tmp-Plots.png")
end
As an alternative (workaround), I want to switch to the “Lucida Grande” font, which comes with macOS, because its “hyphen” is long and thin enough to look like a minus symbol. But adding font="Lucida Grande"
to Figure()
changes only the font used by text!()
and the tick font remains the default one.
https://discourse.julialang.org/t/setting-font-of-minus-sign-in-exponent-in-makie