MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.35k stars 291 forks source link

Allow to add metadata to plotted elements #2885

Open Kolaru opened 1 year ago

Kolaru commented 1 year ago

I am thinking about a PR to give easier access to the internal structure of a figure through iteration over the scene tree and layout tree.

While thinking about it, I realized that if each element had metadata (added at creation, by user or automatically, by Makie or by other package like AlgebraOfGraphics) then the user could filter elements by the metadata without having to understand the internal structure.

The example I have in mind is something like "I want all markers that correspond to a penguin with long beak (query), make them purple with thick stroke (action)".

It could look like

fig = Figure()
# Lot of other plots
ax = Axis(sublayout[3, 5])
scatter!(ax, penguin["size"], penguin["color"] ; metadata = Dict("animal" => "penguin", "beak" => "long"))
# Even more plots

# plot_type would be set automatically at creation or could be special cased
query(fig, Dict("animal" => "penguin", "beak" => "long", "plot_type" => "scatter")) do element
    element.color[] = :purple
    element.strokewidth[] = 2
end
asinghvi17 commented 1 year ago

AFAIK, you can attach metadata to a plot even now.

I'm not sure if the element-wise abstraction would work generically across recipes and input types, though...you could provide an index and the primitive plot, and perhaps provide a macro to make sure that the accessed attributes are actually AbstractVectors with the same length as the input array.

Do you have any other examples of usecases which this might be used for?