sdnetwork#

Plotting and styling for semi-directed phylogenetic networks (SemiDirectedPhyNetwork).

Plotting#

phylozoo.viz.sdnetwork.plot_sdnetwork(network: SemiDirectedPhyNetwork, layout: str = 'twopi', style: SDNetStyle | None = None, ax: Any | None = None, show: bool = False, **layout_kwargs: Any) Any[source]#

Plot a SemiDirectedPhyNetwork.

This is the main public API function for plotting semi-directed networks. It handles layout computation, styling, and rendering using matplotlib.

Parameters:
  • network (SemiDirectedPhyNetwork) – The network to plot.

  • layout (str, optional) – Layout algorithm. PhyloZoo: ‘pz-radial’ (trees only). NetworkX: ‘spring’, ‘circular’, ‘kamada_kawai’, ‘planar’, ‘random’, ‘shell’, ‘spectral’, ‘spiral’, ‘bipartite’. Graphviz: ‘dot’, ‘neato’, ‘fdp’, ‘sfdp’, ‘twopi’, ‘circo’. By default ‘twopi’.

  • 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.sdnetwork import SemiDirectedPhyNetwork
>>> from phylozoo.viz import plot
>>>
>>> net = SemiDirectedPhyNetwork(
...     undirected_edges=[(3, 1), (3, 2)],
...     nodes=[(1, {'label': 'A'}), (2, {'label': 'B'})]
... )
>>> ax = plot(net)

Styling#

Styling for SemiDirectedPhyNetwork plots.

This module provides styling configuration for SemiDirectedPhyNetwork visualizations.

class phylozoo.viz.sdnetwork.style.SDNetStyle(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: MGraphStyle

Styling configuration for SemiDirectedPhyNetwork plots.

This class extends MGraphStyle with SemiDirectedPhyNetwork-specific options, including support for leaves, hybrid nodes, and hybrid edges.

Examples

>>> style = SDNetStyle(node_color='blue', leaf_color='green')
>>> style.node_color
'blue'
copy() SDNetStyle[source]#

Create a copy of this style.

Returns:

A new SDNetStyle instance with the same values.

Return type:

SDNetStyle

Examples

>>> style = SDNetStyle(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.sdnetwork.style.default_style() SDNetStyle[source]#

Get the default style configuration for SemiDirectedPhyNetwork.

Returns:

Default style configuration.

Return type:

SDNetStyle

Examples

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