Skip to content

Allow passing graph level attributes to graphviz #7741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pymc/model_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def make_graph(
figsize=None,
dpi=300,
node_formatters: NodeTypeFormatterMapping | None = None,
graph_attr: dict[str, Any] | None = None,
create_plate_label: PlateLabelFunc = create_plate_label_with_dim_length,
):
"""Make graphviz Digraph of PyMC model.
Expand All @@ -459,7 +460,7 @@ def make_graph(
node_formatters = node_formatters or {}
node_formatters = update_node_formatters(node_formatters)

graph = graphviz.Digraph(name)
graph = graphviz.Digraph(name, graph_attr=graph_attr)
for plate in plates:
if plate.dim_info:
# must be preceded by 'cluster' to get a box around it
Expand Down Expand Up @@ -676,6 +677,7 @@ def model_to_graphviz(
figsize: tuple[int, int] | None = None,
dpi: int = 300,
node_formatters: NodeTypeFormatterMapping | None = None,
graph_attr: dict[str, Any] | None = None,
include_dim_lengths: bool = True,
):
"""Produce a graphviz Digraph from a PyMC model.
Expand Down Expand Up @@ -704,6 +706,10 @@ def model_to_graphviz(
the size of the saved figure.
dpi : int, optional
Dots per inch. It only affects the resolution of the saved figure. The default is 300.
graph_attr : dict, optional
A dictionary of top-level layout attributes for graphviz
Check out graphviz documentation for more information on available attributes
https://graphviz.org/doc/info/attrs.html
node_formatters : dict, optional
A dictionary mapping node types to functions that return a dictionary of node attributes.
Check out graphviz documentation for more information on available
Expand Down Expand Up @@ -773,6 +779,7 @@ def model_to_graphviz(
save=save,
figsize=figsize,
dpi=dpi,
graph_attr=graph_attr,
node_formatters=node_formatters,
create_plate_label=create_plate_label_with_dim_length
if include_dim_lengths
Expand Down
Loading