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:

matplotlib.axes.Axes

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: DMGraphStyle

Styling 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'
copy() DNetStyle[source]#

Create a copy of this style.

Returns:

A new DNetStyle instance with the same values.

Return type:

DNetStyle

Examples

>>> style = DNetStyle(node_color='blue')
>>> style2 = style.copy()
>>> style2.node_color
'blue'
hybrid_color: str = 'lightblue'#
hybrid_edge_color: str = 'red'#
leaf_color: str = 'lightblue'#
leaf_size: float | None = None#
phylozoo.viz.dnetwork.style.default_style() DNetStyle[source]#

Get the default style configuration for DirectedPhyNetwork.

Returns:

Default style configuration.

Return type:

DNetStyle

Examples

>>> style = default_style()
>>> style.node_color
'lightblue'