ytree.visualization.tree_plot.TreePlot
- class ytree.visualization.tree_plot.TreePlot(tree, dot_kwargs=None, node_function=None, edge_function=None)[source]
Make a simple merger tree plot using pydot and graphviz.
- Parameters:
tree (merger tree node
TreeNode) – The merger tree to be plotted.dot_kwargs (optional, dict) – A dictionary of keyword arguments to be passed to pydot.Dot. Default: None.
node_function (optional, function) – A function accepting a single argument of a
TreeNodeand returning a dictionary of keywords to be given to pydot for creating the node object on the plot. This can be used to customize the appearance of the nodes. See examples below. Default: None.edge_function (optional, function) – A function accepting two
TreeNodeobjects and returning a dictionary of keywords to be given to pydot for creating the edge object on the plot (the lines connecting halos). This can be used to customize the appearance of the edges. See examples below. Default: None.
- size_field
The field to determine the size of each circle. Default: ‘mass’.
- Type:
str
- size_log
Whether to scale circle sizes based on log of size field. Default: True.
- Type:
bool
- min_mass
The minimum halo mass to be included in the plot. If given as a float, units are assumed to be Msun. Default: None.
- Type:
float or unyt_quantity
- min_mass_ratio
The minimum ratio between a halo’s mass and the mass of the main halo to be included in the plot. Default: None.
- Type:
float
Examples
>>> import ytree >>> a = ytree.load("tree_0_0_0.dat") >>> p = ytree.TreePlot(a[0]) >>> p.min_mass = 1e6 # Msun >>> p.save()
>>> # customizing nodes >>> import ytree >>> def my_node(halo): ... label = f"{halo['uid']}" ... my_kwargs = {"label": label, "fontsize": 8, "shape": "square"} ... return my_kwargs >>> a = ytree.load("tree_0_0_0.dat") >>> p = ytree.TreePlot(a[0], node_function=my_node) >>> p.save()
>>> # customizing edges >>> import ytree >>> def my_edge(ancestor, descendent): ... if descendent['mass'] < ancestor['mass']: ... color = 'blue' ... else: ... color = 'black' ... my_kwargs = {"color": color, "penwidth": 5} ... return my_kwargs >>> a = ytree.load("tree_0_0_0.dat") >>> p = ytree.TreePlot(a[0], edge_function=my_edge) >>> p.save()
- __init__(tree, dot_kwargs=None, node_function=None, edge_function=None)[source]
Initialize a TreePlot.
Methods
__init__(tree[, dot_kwargs, node_function, ...])Initialize a TreePlot.
save([filename])Save the merger tree plot.
Attributes
The minimum halo mass to be included in the plot.
The minimum halo mass to main halo mass.
The field to determine the size of each circle.
Whether to scale circle sizes based on log of size field.