Styling#
The phylozoo.viz module provides style classes for controlling the visual
appearance of network plots: colors, sizes, and labels.
Using Styles#
Each of the four plottable classes has its own style class:
Styles inherit from a base hierarchy: BaseStyle is the root; DMGraphStyle and MGraphStyle extend it for
the two graph types; DNetStyle extends DMGraphStyle with leaf and hybrid options for directed networks;
SDNetStyle extends MGraphStyle with the same options for semi-directed networks.
Import the style from the corresponding viz submodule:
from phylozoo.viz.dnetwork import DNetStyle
from phylozoo.viz.sdnetwork import SDNetStyle
from phylozoo.viz.d_multigraph import DMGraphStyle
from phylozoo.viz.m_multigraph import MGraphStyle
Each submodule provides a default_style() function that returns a style instance with default values.
If you omit the style argument when calling plot(), the default style for that object type
is used automatically.
Styling Parameters#
BaseStyle#
The BaseStyle class is the base class for all styles. It defines the common attributes for all styles.
node_color (str, default=’lightblue’): Color for nodes. Any valid matplotlib color string is supported.
node_size (float, default=500.0): Size of nodes.
edge_color (str, default=’gray’): Color for edges. Any valid matplotlib color string is supported.
edge_width (float, default=2.0): Width of edges.
with_labels (bool, default=True): Whether to show node labels.
label_offset (float, default=0.12): Offset for labels from nodes.
label_font_size (float, default=10.0): Font size for labels.
label_color (str, default=’black’): Color for labels. Any valid matplotlib color string is supported.
DMGraphStyle and MGraphStyle#
The DMGraphStyle class extends BaseStyle for DirectedMultiGraph.
The MGraphStyle class extends BaseStyle for MixedMultiGraph.
The two classes hold the exact same attributes as BaseStyle, but are defined with future extensibility in mind.
DNetStyle#
Extends DMGraphStyle for DirectedPhyNetwork.
Adds phylogenetic network-specific options:
leaf_color (str, default=’lightblue’): Color for leaf nodes. Any valid matplotlib color string is supported.
hybrid_color (str, default=’lightblue’): Color for hybrid nodes. Any valid matplotlib color string is supported.
leaf_size (float | None, default=None): Size of leaf nodes; if None, uses node_size
hybrid_edge_color (str, default=’red’): Color for hybrid edges. Any valid matplotlib color string is supported.
SDNetStyle#
Extends MGraphStyle for SemiDirectedPhyNetwork.
Adds the same phylogenetic options as DNetStyle:
leaf_color (str, default=’lightblue’): Color for leaf nodes. Any valid matplotlib color string is supported.
hybrid_color (str, default=’lightblue’): Color for hybrid nodes. Any valid matplotlib color string is supported.
leaf_size (float | None, default=None): Size of leaf nodes; if None, uses node_size
hybrid_edge_color (str, default=’red’): Color for hybrid edges. Any valid matplotlib color string is supported.
Example#
The following example loads a network, creates a custom style with several parameters, and plots the result:
from phylozoo import DirectedPhyNetwork
from phylozoo.viz import plot
from phylozoo.viz.dnetwork import DNetStyle
network = DirectedPhyNetwork.load("network.enewick")
style = DNetStyle(
node_color="steelblue",
leaf_color="lightgreen",
hybrid_color="salmon",
hybrid_edge_color="red",
node_size=150,
leaf_size=200,
edge_color="darkgray",
edge_width=2.5,
with_labels=True,
label_font_size=12,
)
plot(network, style=style)
See Also#
Plotting — How to plot with a style
viz API reference — Full style class documentation