Skip to content

Commit f8e24fc

Browse files
ArmavicaricardoV94
authored andcommitted
Explain how to make the graph from to_graphviz
1 parent 109dd50 commit f8e24fc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pymc/model/core.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ def to_graphviz(
19031903
.. code-block:: python
19041904
19051905
import numpy as np
1906-
from pymc import HalfCauchy, Model, Normal, model_to_graphviz
1906+
from pymc import HalfCauchy, Model, Normal
19071907
19081908
J = 8
19091909
y = np.array([28, 8, -3, 7, -1, 1, 18, 12])
@@ -1920,6 +1920,15 @@ def to_graphviz(
19201920
obs = Normal("obs", theta, sigma=sigma, observed=y)
19211921
19221922
schools.to_graphviz()
1923+
1924+
Note that this code automatically plots the graph if executed in a Jupyter notebook.
1925+
If executed non-interactively, such as in a script or python console, the graph
1926+
needs to be rendered explicitly:
1927+
1928+
.. code-block:: python
1929+
1930+
# creates the file `schools.pdf`
1931+
schools.to_graphviz().render("schools")
19231932
"""
19241933
return model_to_graphviz(
19251934
model=self,

pymc/model_graph.py

+9
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,15 @@ def model_to_graphviz(
474474
obs = Normal("obs", theta, sigma=sigma, observed=y)
475475
476476
model_to_graphviz(schools)
477+
478+
Note that this code automatically plots the graph if executed in a Jupyter notebook.
479+
If executed non-interactively, such as in a script or python console, the graph
480+
needs to be rendered explicitly:
481+
482+
.. code-block:: python
483+
484+
# creates the file `schools.pdf`
485+
model_to_graphviz(schools).render("schools")
477486
"""
478487
if "plain" not in formatting:
479488
raise ValueError(f"Unsupported formatting for graph nodes: '{formatting}'. See docstring.")

0 commit comments

Comments
 (0)