TaxonomyMakie — Makie tree visualization

PaleobiologyDB.TaxonomyMakie is a package extension that renders TaxonomyTree objects as rectangular dendrograms in Makie figures. It activates when a Makie backend is loaded.

Installation

pkg> add CairoMakie PhyloPicMakie

Activation

using CairoMakie   # or GLMakie, WGLMakie, …
using PaleobiologyDB
# TaxonomyMakie exports (taxonomytreeplot, augment_tip_phylopic!, etc.) are now in scope

Quick start — basic dendrogram

Build a subtree with taxon_subtree then pass it to taxonomytreeplot:

using CairoMakie
using PaleobiologyDB, PaleobiologyDB.Taxonomy

tree = taxon_subtree("Carnivora"; leaf_rank = "family")

fig, ax, p = taxonomytreeplot(tree; showtips = true)
display(fig)

taxonomytreeplot returns a 3-tuple (fig, ax, plot_object). The x-axis is automatically labelled with rank names at their dendrogram depth positions.

Coloring by rank

Set color_by_rank = true to assign each branch and node a colour based on its taxonomic rank:

fig, ax, p = taxonomytreeplot(tree;
    color_by_rank = true,
    showtips      = true,
)
display(fig)

A custom palette can be supplied as a Dict{String, Any} mapping rank names to any Makie-compatible colour:

palette = Dict(
    "order"  => :steelblue,
    "family" => :darkorange,
    "genus"  => :seagreen,
)

fig, ax, p = taxonomytreeplot(tree;
    color_by_rank = true,
    rank_palette  = palette,
    showtips      = true,
)

Ladderized layout

ladderize = true sorts children of each node by ascending subtree leaf count before the depth-first traversal. Smaller subtrees appear at the top of the plot, giving a cleaner, more asymmetric appearance for trees with unequal branching:

fig, ax, p = taxonomytreeplot(tree;
    ladderize = true,
    showtips  = true,
)

Showing internal node labels

Internal nodes (non-leaf taxa) can be labelled with their taxon names:

fig, ax, p = taxonomytreeplot(tree;
    showinternal      = true,
    internal_fontsize = 7,
    internal_color    = :gray50,
    showtips          = true,
)

Adding to an existing Makie axis

taxonomytreeplot! adds a dendrogram to an axis you have already created, allowing composition with other Makie plots or multi-panel figures:

using CairoMakie
using PaleobiologyDB, PaleobiologyDB.Taxonomy

tree = taxon_subtree("Canidae"; leaf_rank = "genus")

fig = Figure(size = (1000, 700))
ax  = Axis(fig[1, 1]; title = "Canidae genera")

taxonomytreeplot!(ax, tree; showtips = true, ladderize = true)
set_rank_axis_ticks!(ax, tree)

display(fig)

set_rank_axis_ticks! configures the x-axis ticks with rank names. When using the standalone taxonomytreeplot, this is called automatically unless show_rank_ticks = false is passed.

Multi-panel figure combining trees

using CairoMakie
using PaleobiologyDB, PaleobiologyDB.Taxonomy

t_fam = taxon_subtree("Carnivora"; leaf_rank = "family")
t_gen = taxon_subtree("Canidae";   leaf_rank = "genus")

fig = Figure(size = (1400, 600))

ax1 = Axis(fig[1, 1]; title = "Carnivora — families")
taxonomytreeplot!(ax1, t_fam; showtips = true, color_by_rank = true)
set_rank_axis_ticks!(ax1, t_fam)

ax2 = Axis(fig[1, 2]; title = "Canidae — genera")
taxonomytreeplot!(ax2, t_gen; showtips = true, ladderize = true)
set_rank_axis_ticks!(ax2, t_gen)

display(fig)

PhyloPic silhouettes at leaf tips

taxonomytreeplot can overlay PhyloPic silhouette images to the right of each leaf-tip label. This requires FileIO to be loaded in the same session (which also activates PhyloPicMakie):

using CairoMakie
using PaleobiologyDB

Inline mode (default)

Each silhouette appears immediately to the right of its taxon-name label. The horizontal gap is controlled by phylopic_xoffset (in data units):

tree = taxon_subtree("Carnivora"; leaf_rank = "family")

fig, ax, p = taxonomytreeplot(tree;
    showtips         = true,
    show_phylopic    = true,
    phylopic_xoffset = 0.5,
)
display(fig)

The result looks like:

────* Felidae     [IMG]
────* Canidae  [IMG]

Aligned mode

Set phylopic_align = true to place all silhouettes in a single right-hand column, regardless of label length. Increase phylopic_xoffset to control the column's distance from the deepest rank:

fig, ax, p = taxonomytreeplot(tree;
    showtips         = true,
    show_phylopic    = true,
    phylopic_align   = true,
    phylopic_xoffset = 2.0,
)
display(fig)

The result looks like:

────* Felidae                    [IMG]
────* Canidae                    [IMG]
────* Ursidae                    [IMG]

Controlling glyph size and aspect ratio

phylopic_glyph_size sets the half-height of each silhouette in data units (total height = 2 × phylopic_glyph_size). The default 1.0 works well for trees where leaves are spaced 2 units apart (the default row_spacing). Set phylopic_aspect = :stretch to force square glyphs instead of preserving the original image proportions:

fig, ax, p = taxonomytreeplot(tree;
    showtips             = true,
    show_phylopic        = true,
    phylopic_glyph_size  = 0.35,
    phylopic_aspect      = :preserve,   # default — maintains original proportions
)

Handling missing images

Some taxa lack PhyloPic images. The phylopic_on_missing attribute controls what happens:

ValueBehaviour
:skip (default)Silently omit the glyph
:placeholderDraw a translucent grey rectangle in place of the image
:errorThrow an ErrorException
fig, ax, p = taxonomytreeplot(tree;
    show_phylopic       = true,
    phylopic_on_missing = :placeholder,
)

Note on reactivity

PhyloPic images are loaded once when the plot is created. Toggling p[:show_phylopic][] = false after creation hides/shows the existing images without re-downloading. Changing phylopic_glyph_size, phylopic_align, or the tree itself requires recreating the plot with taxonomytreeplot.

Note on extension activation

show_phylopic = true requires the TaxonomyMakie extension to be active, which happens automatically when a Makie backend is loaded alongside PaleobiologyDB. PhyloPicMakie is a hard dependency of PaleobiologyDB and is always available once the package is installed.

Saving figures

Makie's standard save function works with any output format:

fig, ax, p = taxonomytreeplot(tree; showtips = true)

save("carnivora_families.png", fig)
save("carnivora_families.svg", fig)
save("carnivora_families.pdf", fig)

Custom figure and axis options

Pass figure_kwargs and axis_kwargs (named tuples) to control the underlying Figure and Axis:

fig, ax, p = taxonomytreeplot(tree;
    figure_kwargs = (; size = (1200, 900), backgroundcolor = :white),
    axis_kwargs   = (;
        title           = "Carnivora — family-level tree",
        titlesize       = 18,
        xlabel          = "Rank depth",
        xticklabelsize  = 11,
    ),
    showtips      = true,
    color_by_rank = true,
)

Attribute reference

All attributes can be passed as keyword arguments to taxonomytreeplot or taxonomytreeplot!.

AttributeDefaultDescription
ladderizefalseSort children of each node by ascending subtree leaf count
branch_color:blackBranch line colour (used when color_by_rank = false)
branch_linewidth1.5Branch line width in points
show_nodestrueDraw a circular marker at every vertex
node_color:blackNode marker colour (used when color_by_rank = false)
node_size5Node marker size in points
color_by_rankfalseColour branches and nodes by taxonomic rank
rank_palettenothingDict{String,Any} mapping rank → colour; nothing uses the built-in cycle
showtipstrueShow leaf taxon-name labels
tip_fontsize9Leaf label font size in points
tip_color:blackLeaf label colour
tip_xoffset0.5Rightward offset for leaf labels in data units
showinternalfalseShow internal node name labels
internal_fontsize7Internal label font size in points
internal_color:gray40Internal label colour
row_spacing2.0Vertical gap between consecutive leaf rows in data units
show_phylopicfalseDraw a PhyloPic silhouette to the right of each leaf tip (requires FileIO)
phylopic_glyph_size1.0Half-height of each silhouette in data units
phylopic_alignfalsePlace all silhouettes in a single right-hand column
phylopic_xoffset0.65Rightward gap in data units beyond the tip-label start position
phylopic_yoffset0.3Vertical offset for PhyloPic silhouettes in data units (positive = upward)
phylopic_on_missing:skipPolicy when no image is found: :skip, :placeholder, :error
phylopic_aspect:preserve:preserve (original proportions) or :stretch (square)

The following keywords are consumed by taxonomytreeplot (standalone) and are not passed to the recipe:

KeywordDefaultDescription
show_rank_tickstrueCall set_rank_axis_ticks! automatically
figure_kwargs(;)Forwarded to Makie.Figure(; ...)
axis_kwargs(;)Forwarded to Makie.Axis(; ...)