[ANN] Makie.jl 0.19

Makie.jl v0.19 is a small minor release containing only two relevant changes.

First, there’s a breaking change: All occurrences of textsize are now fontsize, so search and replace that word and you will be good to go. The reason is that both of these had been in use for a long time, so we had to pick a moment to clean that up, which is now.

The other change is a new feature. With rich text, you can more easily plot text with more than one font, color or fontsize, as well as superscripts and subscripts. This also fixes the issue with non-matching superscripts in log axes, because these are now small normal glyphs and not special superscript glyphs, which many fonts don’t have (and there aren’t any unicode options for many glyphs you’d want to superscript or subscript, anyway). So now log tick styles will work regardless of font coverage of superscript glyphs. This will also be handy if you want to write simple math expressions in a font other than Computer Modern which is the hardcoded default of MathTexEngine.jl.

Below are a couple examples of rich text. Happy plotting!

using CairoMakie

f = Figure(fontsize = 30)
Label(
    f[1, 1],
    rich(
        "H", subscript("2"), "O is the formula for ",
        rich("water", color = :cornflowerblue, font = :italic)
    )
)

str = "A BEAUTIFUL RAINBOW"
rainbow = cgrad(:rainbow, length(str), categorical = true)
fontsizes = 30 .+ 10 .* sin.(range(0, 3pi, length = length(str)))

rainbow_chars = map(enumerate(str)) do (i, c)
    rich("$c", color = rainbow[i], fontsize = fontsizes[i])
end

Label(f[2, 1], rich(rainbow_chars...), font = :bold)

f

using CairoMakie

f = Figure(fontsize = 30)
Label(
    f[1, 1],
    rich(
        "ITALIC",
        superscript("Regular without x offset", font = :regular),
        font = :italic
    )
)

Label(
    f[2, 1],
    rich(
        "ITALIC",
        superscript("Regular with x offset", font = :regular, offset = (0.15, 0)),
        font = :italic
    )
)

f

Log ticks:

50 Likes

I forgot to mention the other kind-of-breaking change that is also text related! So far, one would often see

f = Figure(..., font = "Arial")

to make a figure where Axis decorations and other text used the font Arial instead of the default TeX Gyre Heros Makie.

But this hasn’t worked well anymore ever since axis titles were bold by default, because there was no way to also change all bold fonts. One would have to go to the attributes of Axis, Axis3, Legend, etc. directly.

Now, the way to go is:

f = Figure(..., fonts = (; regular = "Arial", bold = "Arial bold"))`

Notice it’s fonts instead of font.

Text with font = :regular will resolve to Arial, text with font = :bold will resolve to Arial Bold.
This makes it easier to theme fonts across the figure.

Refer to this part of the docs for more info: https://docs.makie.org/stable/documentation/fonts/index.html

9 Likes

Since we don’t have announcement posts for patch versions we should probably mention the important changes that happened between 0.18 - 0.19 too.

From my side there have been two GLMakie changes worth mentioning. The first is the removal of the stencil buffer in GLMakie, which has been limiting us to 255 scenes. Since blocks (Menu, Axis, etc) use at least one scene each, this also placed a limit on those, which reachable in more verbose dashboards.

The second is the introduction of render_on_demand as the new default rendering mode in GLMakie. With it rendering only happens when there is actually a visual change, rather than 30 times a second. If you’ve been annoyed by GLMakie draining your battery and/or putting your fans into overdrive, this is the change for you. And if you’ve been using it to heat your room, you can go back with display(fig, render_on_demand=false).

20 Likes

Good point, those were really good improvements!

Great release and announcement.

I still think that Makie.org should have a RSS feed.

Thank you for pointing that out. All my code has GLMakie.set_window_config!(framerate=5.0) because of the fan noise problem - can I leave that out from now on?

Thanks for all the great work!

1 Like

Try it, but very likely yes :wink:

Yes, it works well without having to reduce the frame rate. That’s a huge improvement - thanks again!

It appears the Figure(font = texfont()) trick from MathTeXEngine no longer uses the correct tex font for the figure elements. Is this an intentional change?

As described in my second post above, use Figure(fonts = (; regular = texfont()). The Blocks all set font = :regular and font = :bold now and don’t inherit from the global font setting anymore.

1 Like

These are all great improvements! I like especially the textsize → fontsize one. Thanks!

Does Makie’s new rich text support work with LaTeX string too? E.g. is there a way to do rich(L"a^2", color=:blue)?

No, currently those two types are separate.

1 Like

Makes sense. Thanks!

In principle it could be made to work “easily” as in, both lower to the same glyph representations. But we’d have to adjust the layouting algorithms so they can deal with the mixtures in a way that makes sense. And I foresee that that could be not completely trivial

2 Likes