causalnex.plots.plot_structure(sm, prog='neato', all_node_attributes=None, all_edge_attributes=None, node_attributes=None, edge_attributes=None, graph_attributes=None)[source]

Plot a StructureModel using pygraphviz.

Return a pygraphviz graph from a StructureModel. The pygraphgiz graph is decorated and laid out so that it can be plotted easily.

Default node, edge, and graph attributes are provided to style and layout the plot. These defaults can be overridden for all nodes and edges through all_node_attributes and all_edge_attributes respectively. Graph attributes can be overridden through graph_attributes.

Styling and layout attributes can be set for individual nodes and edges through node_attributes and edge_attributes respectively.

Attributes are set in the following order, overriding any previously set attributes 1. default attributes 2. all_node_attributes and all_edge_attributes 3. node_attributes and edge_attributes 4. graph_attributes

Detailed documentation on available attributes and how they behave is available at:

Default style attributes provided in CausalNex are:

  • causalnex.plots.NODE_STYLE.NORMAL - default node stying

  • causalnex.plots.NODE_STYLE.WEAK - intended for less important nodes in structure

  • causalnex.plots.NODE_STYLE.STRONG - intended for more important nodes in structure

  • causalnex.plots.EDGE_STYLE.NORMAL - default edge stying

  • causalnex.plots.EDGE_STYLE.wEAK - intended for less important edges in structure

  • causalnex.plots.EDGE_STYLE.STRONG - intended for more important edges in structure

  • causalnex.plots.GRAPH_STYLE - default graph styling


from causalnex.plots import plot_structure
plot = plot_structure(structure_model)
  • sm (DiGraph) – structure to plot

  • prog (str) – Name of Graphviz layout program

  • all_node_attributes (Optional[Dict[str, str]]) – attributes to apply to all nodes

  • all_edge_attributes (Optional[Dict[str, str]]) – attrinbutes to apply to all edges

  • node_attributes (Optional[Dict[str, Dict[str, str]]]) – attributes to apply to specific nodes

  • edge_attributes (Optional[Dict[Tuple[str, str], Dict[str, str]]]) – attributes to apply to specific edges

  • graph_attributes (Optional[Dict[str, str]]) – attributes to apply to the graph


a styled pygraphgiz graph that can be rendered as an image


Warning – Suggests mitigation strategies when pygraphviz is not installed.