dnetwork#
Plotting and styling for directed phylogenetic networks (DirectedPhyNetwork).
Plotting#
- phylozoo.viz.dnetwork.plot_dnetwork(network: DirectedPhyNetwork, layout: str = 'pz-dag', style: DNetStyle | None = None, ax: Any | None = None, show: bool = False, **layout_kwargs: Any) Any[source]#
Plot a DirectedPhyNetwork.
This is the main public API function for plotting networks. It handles layout computation, styling, and rendering using matplotlib.
- Parameters:
network (DirectedPhyNetwork) – The network to plot.
layout (str, optional) – Layout algorithm. PhyloZoo: ‘pz-dag’. NetworkX: ‘spring’, ‘circular’, ‘kamada_kawai’, ‘planar’, ‘random’, ‘shell’, ‘spectral’, ‘spiral’, ‘bipartite’. Graphviz: ‘dot’, ‘neato’, ‘fdp’, ‘sfdp’, ‘twopi’, ‘circo’. By default ‘pz-dag’.
style (NetworkStyle, optional) – Styling configuration. If None, uses default style. By default None.
ax (matplotlib.axes.Axes, optional) – Existing axes to plot on. If None, creates new figure and axes. By default None.
show (bool, optional) – If True, automatically display the plot using plt.show(). By default False.
**layout_kwargs – Additional parameters for layout computation.
- Returns:
The axes object containing the plot.
- Return type:
- Raises:
PhyloZooLayoutError – If layout algorithm is not supported.
Examples
>>> from phylozoo.core.network.dnetwork import DirectedPhyNetwork >>> from phylozoo.viz import plot >>> >>> net = DirectedPhyNetwork( ... edges=[(3, 1), (3, 2)], ... nodes=[(1, {'label': 'A'}), (2, {'label': 'B'})] ... ) >>> ax = plot(net)
Styling#
Styling for DirectedPhyNetwork plots.
This module provides styling configuration for DirectedPhyNetwork visualizations.
- class phylozoo.viz.dnetwork.style.DNetStyle(node_color: str = 'lightblue', node_size: float = 500.0, node_edge_color: str = 'black', node_edge_width: float = 1.5, edge_color: str = 'gray', edge_width: float = 2.0, with_labels: bool = True, label_offset: float = 0.12, label_font_size: float = 10.0, label_color: str = 'black', leaf_color: str = 'lightblue', hybrid_color: str = 'lightblue', leaf_size: float | None = None, hybrid_edge_color: str = 'red')[source]#
Bases:
DMGraphStyleStyling configuration for DirectedPhyNetwork plots.
This class extends DMGraphStyle with DirectedPhyNetwork-specific options, including support for leaves, hybrid nodes, and hybrid edges.
Examples
>>> style = DNetStyle(node_color='blue', leaf_color='green') >>> style.node_color 'blue'