causalnex.plots.plot_structure

causalnex.plots.plot_structure(g, ax=None, title=None, show_labels=True, node_color='r', edge_color='k', label_color='k', node_positions=None)[source]

Plot the structure model to visualise the relationships between nodes.

Parameters:
  • g (StructureModel) – the structure model to plot.
  • ax (Optional[Axes]) – if provided then figure will be drawn to this Axes, otherwise a new Axes will be created.
  • title (Optional[str]) – if provided then the title will be drawn on the plot.
  • show_labels (bool) – if True then node labels will be drawn.
  • node_color (str) – a single color format string, for example ‘r’ or ‘#ff0000’. default “r”.
  • edge_color (str) – a single color format string, for example ‘r’ or ‘#ff0000’. default “k”.
  • label_color (str) – a single color format string, for example ‘r’ or ‘#ff0000’. default “k”.
  • node_positions (Optional[Dict[str, List[float]]]) – coordinates for node positions, ie {“node_a”: [0, 0]}.
Return type:

Tuple[Figure, Axes, Dict[str, List[float]]]

Returns:

fig, ax, node_positions.

Example:

# Create a Bayesian Network with a manually defined DAG.
from causalnex.structure import StructureModel
from causalnex.network import BayesianNetwork

sm = StructureModel()
sm.add_edges_from([
                   ('rush_hour', 'traffic'),
                   ('weather', 'traffic')
                   ])
from causalnex.plots import plot_structure
plot_structure(sm)