[ANN] MakieExtra.jl – more recipes and tools for Makie plots

The promised new feature is:

FPlot: composable plotting specification

What started as a simple proof of concept in the #makie channel several months ago – now became the primary way I do plotting.
I believe it is generally a nice way to do basically all kinds of plots, aside from images/volumes/similar stuff.

The design of most plotting libraries, including Makie, tends to take different properties of the plot (xy coordinates, color, size, …) as separate arrays. This is convenient for tiny self-contained snippets, hard to argue with the simplicity of scatter(rand(100), rand(100)). However, this approach feels suboptimal for anything even slightly more complicated.

It’s very common that one has a dataset – a collection of elements – and thinks of plotting in terms of these elements. Like, "for r ∈ data, plot abs(r.value) along the x axis, angle(r.value) along the y axis, and color them by r.age.
FPlot is an object that encapsulates the whole plot definition – the dataset, xy mapping, and mappings for other attributes like color.

FPlot(
	dataset,
	r->abs(r.value), r->angle(r.value);  # what to plot on x and y axes 
	color=r->r.age,  # mappings for any keyword arguments
)

As FPlot “knows” what is shown along axes, it can automatically set axis labels – lines(FPlot(data, (@o _.a), (@o _.b))) results in this:


It also naturally leads to reusing/modifying the same FPlot for multiple views into a dataset, and makes basic composable interactivity possible with a few lines of code:

See a more detailed overview and more examples in the docs.

Try playing with FPlot to get a feeling how it works, I should say it becomes very natural quickly :slight_smile:
Suggestions for a better name are welcome!

6 Likes

Just on this, I’ve been campaigning for use of StyledStrings for this, and I think I’ll continue to do so :grin:.

Here’s an API I’d put to you all:

# Current Makie
rich("a", subscript("x"), ": ", rich(a, font=:bold), ", b: ", rich(b, font=:italic))
# MakieExtra
"a" * subscript("x") * ": " * rich(a, font=:bold) * ", b: " * rich(b, font=:italic)
@rich "a$(subscript("x")): $(rich(a, font=:bold)), b: $(rich(b, font=:italic))"
# Proposed
styled"a{_:x}: {bold:$a}, b: {italic:$b}"
4 Likes

In general yes, would be nice to have a consistent interface for rich text to be used across different Julia packages.
It’s just that in this thread, I only highlight already existing features, something that one could use right now. The implementation in MakieExtra is extremely simple, just a few lines.
AFAIK, StyledStrings cannot be currently used in Makie. Also, all those annotated strings are an experimental API that has a different behavior between Julia versions. That’s another difference from Makie rich text, something one should also be careful about…

1 Like

I think it would be worth waiting till I can put together another compat release to reflect a few of the changes that slipped into 1.11 last-minute, but I don’t see any hard reason why not: the compat/1.11 differences don’t affect what I think Makie would need to use

Anyway, as you say — not something you can do anything about, but I’m excited about where this can lead and I like to take opportunities to share that with other people :slight_smile:

4 Likes