# Makie: defaulting to minus symbol everywhere?

**URL:** https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291
**Category:** Visualization
**Tags:** question, makie
**Created:** [November 16, 2023, 3:30am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291 "2023-11-16T03:30:26Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)
#### Post date: [November 16, 2023, 3:30am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/1 "2023-11-16T03:30:26Z")

</div>

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:

```julia
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](https://discourse.julialang.org/t/setting-font-of-minus-sign-in-exponent-in-makie)

---

<div class="post-metadata">

### Author: ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)
#### Post date: [November 16, 2023, 4:16am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/2 "2023-11-16T04:16:35Z")

</div>

FWIW, my workaround is to `replace(..., "-"=>"−")` the hyphens “manually”. E.g., on the axis tick labels, you can do

```julia
f = Figure(resolution=(300,300))
ax = Axis(f[1,1], xtickformat = x -> [replace(string(x), "-"=>"−") for x in x])
lines!(ax, -10:10, -10:10)
f

```

which gives (note the minuses of the x-axis vs the y-axis)

 ![](https://global.discourse-cdn.com/julialang/original/3X/9/a/9a2eb9ce39d0d8ee660f630fb1bbadf19a749b09.png)

---

<div class="post-metadata">

### Author: ![tecosaur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tecosaur/32/23206_2.png) [@tecosaur](https://discourse.julialang.org/u/tecosaur)
#### Post date: [November 16, 2023, 6:12am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/3 "2023-11-16T06:12:51Z")

</div>

Arguably, shouldn’t Makie itself default to minus instead of hyphen?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 16, 2023, 6:31am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/4 "2023-11-16T06:31:31Z")

</div>

I had a PR doing this change once but it was not accepted. Mostly because it’s breaking and the minus takes more space so you get collisions more easily.

Also you could write a meta formatter which formats tick labels according to some other formatter but then replaces the hyphen with minus as shown above

---

<div class="post-metadata">

### Author: ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)
#### Post date: [November 16, 2023, 7:00am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/5 "2023-11-16T07:00:07Z")

</div>

Thank you everyone for your help and inputs.

> breaking

I understand, but I wonder whether it is difficult to introduce a switch instead of changing the default?

> get collisions more easily

I already get a lot of collisions 🙂 without changing the formatters. Unfortunately, collisions seem to be something the user have to manually avoid in any case. (Of course, I’m not missing your point of “_more_ easily”. My point is that the potentially increased frequency of collisions shouldn’t be regarded as an impediment to the introduction of the minus symbol.)

[By the way, currently I want to change the minus symbol on a colorbar, which means I have to find out the name of the formatter of the colorbar . . . And what about the global font change? If I can switch all the fonts to “Lucida Grande”, I can forget about this issue 🙂]

---

<div class="post-metadata">

### Author: ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)
#### Post date: [November 16, 2023, 7:10am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/6 "2023-11-16T07:10:24Z")

</div>

> [@jules](#):
>
> a meta formatter which formats tick labels according to some other formatter

That’s exactly what I was thinking of when I was saying I might be writing a custom formatter. How do you get hold of the result of the default formatter for you to modify? If I knew the name of the default formatter, then I imagine this is what I would do:

```julia
myformatter(xs) = replace.(MakieDefaultFormatter(xs), "-" => "−")

```

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 16, 2023, 7:26am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/7 "2023-11-16T07:26:32Z")

</div>

This should answer both questions:

```julia
Base.@kwdef struct HyphenFormat
    wrapped = Makie.automatic
end

function Makie.get_ticks(ticks, scale, formatter::HyphenFormat, vmin, vmax)
    ticks, labels = Makie.get_ticks(ticks, scale, formatter.wrapped, vmin, vmax)
    return ticks, replace.(labels, "-" => "−")
end

f = Figure(; fonts = (; regular = "Comic Sans", bold = "Times Bold"))
ax = Axis(f[1, 1], title = "Bold font", xtickformat = HyphenFormat())
scatter!(ax, randn(100, 2))
f

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/8/1/818686ff473b6b8722b98343da01311ffbb9f643.png)

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 16, 2023, 8:22am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/8 "2023-11-16T08:22:58Z")

</div>

> [@ryofurue](#):
>
> Unfortunately, collisions seem to be something the user have to manually avoid in any case.

We can detect if collisions happen, but we cannot really change ticks depending on size in layout because the ticks influence the layout so you get a cycle.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 16, 2023, 12:51pm UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/10 "2023-11-16T12:51:24Z")

</div>

> [@ryofurue](#):
>
> Basically, I want all numeric labels and letterings for negative numbers to use the unicode _minus_ symbol, not the ASCII hyphen character.

[Matplotlib does this](https://matplotlib.org/stable/gallery/text_labels_and_annotations/unicode_minus.html), with an option to turn it off; it’s a shame that Makie doesn’t follow suit. Using a hyphen seems like poor typography here.

> [@jules](#):
>
> I had a PR doing this change once but it was not accepted. Mostly because it’s breaking and the minus takes more space so you get collisions more easily.

Are you referring to [Makie#2321](https://github.com/MakieOrg/Makie.jl/pull/2321)? My understanding is that the hyphen change wasn’t rejected outright, but was [requested to be put into a separate PR](https://github.com/MakieOrg/Makie.jl/pull/2321#issuecomment-1293332647) rather than being a small part of a much larger PR, so that it could be discussed/evaluated on its own.

---

<div class="post-metadata">

### Author: ![tecosaur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tecosaur/32/23206_2.png) [@tecosaur](https://discourse.julialang.org/u/tecosaur)
#### Post date: [November 16, 2023, 12:53pm UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/11 "2023-11-16T12:53:59Z")

</div>

I have a second cent on this, that is: should tick labels be so closely packed that a hyphen/minus symbol makes the difference between overlap and no overlap, the plot has bigger issues.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 16, 2023, 1:17pm UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/12 "2023-11-16T13:17:08Z")

</div>

well, sure, but in a normal sentence you also rely on gaps about the size difference between hyphen and minus glyph to break the words apart 🙂 Sonothavingthatgapcanmakequitethedifference

Anyway, as you can see from that old PR I was never opposed to minus glyphs

> Are you referring to [Makie#2321](https://github.com/MakieOrg/Makie.jl/pull/2321)

Not just that, also conversations off github. I guess the time to change it could be now because it could be bundled up with all the others in 0.20 @sdanisch ?

---

<div class="post-metadata">

### Author: ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)
#### Post date: [November 17, 2023, 3:37am UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/13 "2023-11-17T03:37:39Z")

</div>

Thank you! This is off topic, but just to correct myself:

> `fonts`

I thought that didn’t work for me and that was the reason why I asked the question. But staring at your code, I finally discovered that I spelt it as `font` (because I thought you just set one default font). Incidentally, in a different context, I recently found that `Makie` silently ignores unknown keywords, which was why I didn’t realize my misspelling.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 22, 2023, 1:58pm UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/14 "2023-11-22T13:58:33Z")

</div>

We switched to the minus symbol in Makie 0.20

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 22, 2023, 3:53pm UTC](https://discourse.julialang.org/t/makie-defaulting-to-minus-symbol-everywhere/106291/15 "2023-11-22T15:53:13Z")

</div>

In particular:

> <https://github.com/MakieOrg/Makie.jl/pull/3379>
>
> Before:
> 
> \<img width="567" alt="grafik" src="https://github.com/MakieOrg/Makie.…jl/assets/22495855/df8273aa-f806-4d5e-a91e-841430b3b7b0"\>
> 
> After:
> 
> \<img width="568" alt="grafik" src="https://github.com/MakieOrg/Makie.jl/assets/22495855/41e48dc3-c974-4096-b132-b744acfac643"\>
