treelabels
Use treelabels! to annotate nodes with labels
tree = ((:a, :b), (:c, (:d, :e)))
fig, ax, tp = treeplot(tree)
treelabels!(tp)
fig
By default it will use BasicTreePlots.tipannotations(tp.nodepoints) and plot BasicTreePlots.label(leaf) for each leaf.
Nodelabels
List of nodes and associated labels for which to plot. Should be an iterable where each element is a pair or tuple of node => label. Basically [(node, label) for (node, label) in nodelabels] should not error and provide each node and label you want plotted.
tree = ((:a, :b), (:c, (:d, :e)))
fig, ax, tp = treeplot(tree)
treelabels!(tp; nodelabels = [
tree[1] => "A and B",
(:c, (:d, :e)) => "C, D, E",
:a => "A",
:c => "C",
:d => "D",
])
fig
Nodes not provided will not have annotations added.
Depth
Available options:
nothing(default) in which case the anchorpoints for the labels are directly on the nodes being labeled.depth=:align, Places the anchorpoints at a constant depth equal to the leaf node maximally distant from the root.depth=<:Real, sets the custom constant depth at which the label anchorpoints are set.depth=(node,pos)->Point2f, Determines a custom function that takes a node and its coordinate and returns where the label anchorpoint should be.
tree = ((:a, :b), (:c, (:d, :e)))
nodelabels = [tree[1] => "A and B", (:c, (:d, :e)) => "C, D, E", :a => "A", :c => "C", :d => "D"]
fig = Figure(size=(900, 300))
ax, tp = treeplot(fig[1,1], tree, axis=(; xautolimitmargin=(0.05, 0.4)))
hidedecorations!(ax)
treelabels!(tp; nodelabels, depth=:align)
ax, tp = treeplot(fig[1,2], tree, axis=(; xautolimitmargin=(0.05, 0.4)))
hidedecorations!(ax)
treelabels!(tp; nodelabels, depth=tp.maxtreedepth)
ax, tp = treeplot(fig[1,3], tree, axis=(; xautolimitmargin=(0.05, 0.2)))
hidedecorations!(ax)
treelabels!(tp; nodelabels, depth=(node, pos) -> let
BasicTreePlots.isleaf(node) ? Point2f(tp.maxtreedepth[], pos[2]) : pos
end)
fig
Label rotation
Options are :horizontal, :radial, :aligned, or a number θ<:Real in radians. If automatic, will default to :aligned on polar axis and :horizontal otherwise.
Rotation examples on Axis plot
tree = ((:a, :b), (:c, (:d, :e)))
nodelabels = [tree[1] => "A and B", (:c, (:d, :e)) => "C, D, E", :a => "A", :c => "C", :d => "D"]
fig = Figure(size=(600, 300))
ax, tp = treeplot(fig[1,1], tree, axis=(;
title="labelrotation = :horizontal",
xautolimitmargin=(0.05, 0.4))
)
treelabels!(tp; nodelabels, labelrotation = :horizontal)
ax, tp = treeplot(fig[1,2], tree, axis=(;
title="labelrotation = deg2rad(45)",
xautolimitmargin=(0.05, 0.4))
)
treelabels!(tp; nodelabels, labelrotation = deg2rad(45))
fig
Rotation examples on PolarAxis plot
tree = ((:a, :b), (:c, (:d, :e)))
nodelabels = [
tree[1] => "A and B", (:c, (:d, :e)) => "C, D, E",
:a => "A", :b => "B", :c => "C", :d => "D", :e => "E"
]
fig = Figure(size=(600, 300))
ax, tp = treeplot(fig[1,1], tree, axis=(;
type=PolarAxis,
title="labelrotation = :aligned",
rautolimitmargin=(0.0, 0.4))
)
hidedecorations!(ax)
treelabels!(tp; nodelabels, labelrotation = :aligned)
ax, tp = treeplot(fig[1,2], tree, axis=(;
type=PolarAxis,
title="labelrotation = :radial",
rautolimitmargin=(0.0, 0.4))
)
hidedecorations!(ax)
treelabels!(tp; nodelabels, labelrotation = :radial)
fig
Label alignment
determines where on the textbox is anchored to the anchorpoint, useful when plotting the tree in different orientations
fig = Figure(size=(400, 400))
ax, tp = treeplot(fig[1,1], tree,
orientation=:bottom,
axis=(;
yautolimitmargin=(0.2, 0.05)
)
)
treelabels!(tp; nodelabels,
labelrotation = deg2rad(45),
labelalign=(:right, :center),
labeloffset=(0.0, -10),
)
fig
Label offset
Offset in pixel space to push text label anchor points. Available options:
automatic(default) if plotting onAxis()the offset is (5px, 0), if onPolarAxis()the default is5px * (cos(θ), sin(θ))where θ is the radian angle of the node.labeloffset::Realdefaults to offsetting the label in pixels toward the x direction forAxisand in radius forPolarAxis`labeloffset=Tuple{<:Real, <:Real}, if plotting on anAxisprovide(x,y), if onPolarAxisprovide(θ, r)in pixel units for the offset relative to the label anchorpoint.labeloffset::Function=(node,pos)->(x_px, y_px), Provide a custom function that takes a node and its coordinate in dataspace and return a pixel space offset. Note that pixel space does not get converted like thePolarAxis, so conversion of coordinates may be requiredr_off * (cos(θ+θ_off), sin(θ+θ_off)).
fig = Figure(size=(900,600))
ax, tp = treeplot(fig[1,1], tree; axis=(;
xautolimitmargin=(0.05, 0.15),
title="labeloffset=automatic"
)
)
hidedecorations!(ax)
treelabels!(tp; nodelabels)
ax, tp = treeplot(fig[2,1], tree;
axis=(;
type=PolarAxis,
rautolimitmargin=(0.0, 0.3),
title="labeloffset=automatic"
)
)
hidedecorations!(ax)
treelabels!(tp; nodelabels)
ax, tp = treeplot(fig[1,2], tree; axis=(;
xautolimitmargin=(0.05, 0.15),
title="labeloffset=(20, 0)"
)
)
hidedecorations!(ax)
treelabels!(tp; nodelabels, labeloffset=(20, 0))
ax, tp = treeplot(fig[2,2], tree;
axis=(;
type=PolarAxis,
rautolimitmargin=(0.0, 0.4),
title="labeloffset=(0, 20)"
)
)
hidedecorations!(ax)
treelabels!(tp; nodelabels, labeloffset=(0, 20))
ax, tp = treeplot(fig[1,3], tree; axis=(;
xautolimitmargin=(0.05, 0.15),
title="labeloffset=function"
)
)
hidedecorations!(ax)
treelabels!(tp; nodelabels, labeloffset=(node, pos)->let
BasicTreePlots.isleaf(node) ? (20, 0) : (-55, 10)
end)
ax, tp = treeplot(fig[2,3], tree;
axis=(;
type=PolarAxis,
rautolimitmargin=(0.0, 0.3),
title="labeloffset=function"
)
)
hidedecorations!(ax)
treelabels!(tp; nodelabels, labeloffset=(node,pos)-> let
BasicTreePlots.isleaf(node) ? 5 .* (cos(pos[1]), sin(pos[1])) : 25 .* (cos(pos[1])+deg2rad(-10), sin(pos[1]+deg2rad(-10)))
end)
fig
Label guideline styling
If guidesvisible=true (default) draw guide lines from node to label anchorpoint. Useful for visually connecting leaves to their location on the y axis (or θ axis if plotted on PolarAxis), especially when using the depth attribute.
fig = Figure(size=(600, 300))
ax, tp = treeplot(fig[1,1], tree; axis=(;title="No guides", xautolimitmargin=(0.05, 0.2)))
hidedecorations!(ax)
treelabels!(tp; depth=:align, guidesvisible=false)
ax, tp = treeplot(fig[1,2], tree; axis=(;title="Styled guides", xautolimitmargin=(0.05, 0.2)))
hidedecorations!(ax)
treelabels!(tp; depth=:align, guideswidth=3, guidescolor=:magenta, guidesstyle=:dash)
fig
Reference
BasicTreePlots.treelabels — Function
Adds text labels associated to particular nodes in a tree already plotted with treeplot
Examples
Defaults to labeling the leaves of the tree based on BasicTreePlots.label(leafnode)
ax, p = treeplot(tree)
treelabels!(p.nodepoints)Also possible to specify a subset of nodes with custom labels
ax, p = treeplot(tree)
treelabels!(p.nodepoints; nodelabels=Dict(node1 => "Node 1", node_a => "My special node"))Plot type
The plot type alias for the treelabels function is TreeLabels.
Attributes
clip_planes = @inherit clip_planes automatic — Clip planes offer a way to do clipping in 3D space. You can set a Vector of up to 8 Plane3f planes here, behind which plots will be clipped (i.e. become invisible). By default clip planes are inherited from the parent plot or scene. You can remove parent clip_planes by passing Plane3f[].
depth = nothing — Available options: nothing (default) in which case the anchorpoints for the labels are directly on the nodes being labeled. depth=:align, Places the anchorpoints at a constant depth equal to the leaf node maximally distant from the root. depth=<:Real, sets the custom constant depth at which the label anchorpoints are set. depth=(node,pos)->Point2f, Determines a custom function that takes a node and its coordinate and returns where the label anchorpoint should be.
depth_shift = 0.0 — Adjusts the depth value of a plot after all other transformations, i.e. in clip space, where -1 <= depth <= 1. This only applies to GLMakie and WGLMakie and can be used to adjust render order (like a tunable overdraw).
font = @inherit font :regular — Font of the text labels
fontsize = @inherit fontsize 9.0f0 — Font size of the node labels
fxaa = true — Adjusts whether the plot is rendered with fxaa (fast approximate anti-aliasing, GLMakie only). Note that some plots implement a better native anti-aliasing solution (scatter, text, lines). For them fxaa = true generally lowers quality. Plots that show smoothly interpolated data (e.g. image, surface) may also degrade in quality as fxaa = true can cause blurring.
guidescolor = :lightgray — Line color of the guide lines
guidesstyle = :solid — Line style of the guide lines
guidesvisible = true — If true draw guide lines from node to label anchorpoint. Useful for visually connecting leaves to their location on the y axis (or θ axis if plotted on PolarAxis), especially when using the depth attribute.
guideswidth = 0.5 — Line width of the guide lines
inspectable = @inherit inspectable — Sets whether this plot should be seen by DataInspector. The default depends on the theme of the parent scene.
inspector_clear = automatic — Sets a callback function (inspector, plot) -> ... for cleaning up custom indicators in DataInspector.
inspector_hover = automatic — Sets a callback function (inspector, plot, index) -> ... which replaces the default show_data methods.
inspector_label = automatic — Sets a callback function (plot, index, position) -> string which replaces the default label generated by DataInspector.
labelalign = automatic — Text alignment of labels to anchor points, Is overridden when labelrotation=:aligned (default).
labeloffset = automatic — Offset in pixel space to push text label anchor points. Available options: automatic (default) if plotting on Axis() the offset is (5px, 0), if on PolarAxis() the default is 5px * (cos(θ), sin(θ)) where θ is the radian angle of the node. labeloffset::Real defaults to offsetting the label in pixels toward the x direction for Axisand in radius forPolarAxislabeloffset=Tuple{<:Real, <:Real}, if plotting on anAxisprovide(x,y), if onPolarAxisprovide(θ, r)in pixel units for the offset relative to the label anchorpoint.labeloffset::Function=(node,pos)->(x px, y px), Provide a custom function that takes a node and its coordinate in dataspace and return a pixel space offset. Note that pixel space does not get converted like thePolarAxis, so conversion of coordinates may be requiredroff * (cos(θ+θoff), sin(θ+θ_off))`.
labelrotation = automatic — Options are :horizontal, :radial, :aligned, or a number θ<:Real in radians. If automatic, will default to :aligned on polar axis and :horizontal otherwise.
model = automatic — Sets a model matrix for the plot. This overrides adjustments made with translate!, rotate! and scale!.
nodelabels = nothing — List of nodes and associated labels for which to plot. Should be an iterable where each element is a pair node => label. Basically [(node, label) for (node, label) in nodelabels] should not error and provide each node and label you want plotted.
If nothing will default to BasicTreePlots.tipannotations(nodepoints) and plot BasicTreePlots.label(leaf) for each leaf
Nodes should have coordinates accessible via nodepoints[node]. These coordinates can be calculated with tp = treeplot!(tree) and accessed with tp.nodepoints.
overdraw = false — Controls if the plot will draw over other plots. This specifically means ignoring depth checks in GL backends
space = :data — Sets the transformation space for box encompassing the plot. See Makie.spaces() for possible inputs.
ssao = false — Adjusts whether the plot is rendered with ssao (screen space ambient occlusion). Note that this only makes sense in 3D plots and is only applicable with fxaa = true.
transformation = :automatic — Controls the inheritance or directly sets the transformations of a plot. Transformations include the transform function and model matrix as generated by translate!(...), scale!(...) and rotate!(...). They can be set directly by passing a Transformation() object or inherited from the parent plot or scene. Inheritance options include:
:automatic: Inherit transformations if the parent and childspaceis compatible:inherit: Inherit transformations:inherit_model: Inherit only model transformations:inherit_transform_func: Inherit only the transform function:nothing: Inherit neither, fully disconnecting the child's transformations from the parent
Another option is to pass arguments to the transform!() function which then get applied to the plot. For example transformation = (:xz, 1.0) which rotates the xy plane to the xz plane and translates by 1.0. For this inheritance defaults to :automatic but can also be set through e.g. (:nothing, (:xz, 1.0)).
transparency = false — Adjusts how the plot deals with transparency. In GLMakie transparency = true results in using Order Independent Transparency.
visible = true — Controls whether the plot gets rendered or not.