diff --git a/pymc/distributions/shape_utils.py b/pymc/distributions/shape_utils.py index 6e3b85beb8..e5eb435a95 100644 --- a/pymc/distributions/shape_utils.py +++ b/pymc/distributions/shape_utils.py @@ -109,6 +109,7 @@ def broadcast_dist_samples_shape(shapes, size=None): Examples -------- .. code-block:: python + size = 100 shape0 = (size,) shape1 = (size, 5) @@ -116,7 +117,9 @@ def broadcast_dist_samples_shape(shapes, size=None): out = broadcast_dist_samples_shape([shape0, shape1, shape2], size=size) assert out == (size, 4, 5) + .. code-block:: python + size = 100 shape0 = (size,) shape1 = (5,) @@ -124,7 +127,9 @@ def broadcast_dist_samples_shape(shapes, size=None): out = broadcast_dist_samples_shape([shape0, shape1, shape2], size=size) assert out == (size, 4, 5) + .. code-block:: python + size = 100 shape0 = (1,) shape1 = (5,) diff --git a/pymc/model/core.py b/pymc/model/core.py index fecde43df4..d0e4556426 100644 --- a/pymc/model/core.py +++ b/pymc/model/core.py @@ -1873,7 +1873,7 @@ def to_graphviz( .. code-block:: python import numpy as np - from pymc import HalfCauchy, Model, Normal, model_to_graphviz + from pymc import HalfCauchy, Model, Normal J = 8 y = np.array([28, 8, -3, 7, -1, 1, 18, 12]) @@ -1890,6 +1890,15 @@ def to_graphviz( obs = Normal("obs", theta, sigma=sigma, observed=y) schools.to_graphviz() + + Note that this code automatically plots the graph if executed in a Jupyter notebook. + If executed non-interactively, such as in a script or python console, the graph + needs to be rendered explicitly: + + .. code-block:: python + + # creates the file `schools.pdf` + schools.to_graphviz().render("schools") """ return model_to_graphviz( model=self, diff --git a/pymc/model_graph.py b/pymc/model_graph.py index 009c54a298..7f356eb479 100644 --- a/pymc/model_graph.py +++ b/pymc/model_graph.py @@ -474,6 +474,15 @@ def model_to_graphviz( obs = Normal("obs", theta, sigma=sigma, observed=y) model_to_graphviz(schools) + + Note that this code automatically plots the graph if executed in a Jupyter notebook. + If executed non-interactively, such as in a script or python console, the graph + needs to be rendered explicitly: + + .. code-block:: python + + # creates the file `schools.pdf` + model_to_graphviz(schools).render("schools") """ if "plain" not in formatting: raise ValueError(f"Unsupported formatting for graph nodes: '{formatting}'. See docstring.") diff --git a/pymc/pytensorf.py b/pymc/pytensorf.py index a9c1b6bc26..ef4aa2a157 100644 --- a/pymc/pytensorf.py +++ b/pymc/pytensorf.py @@ -808,6 +808,7 @@ def collect_default_updates( Examples -------- .. code:: python + import pymc as pm from pytensor.scan import scan from pymc.pytensorf import collect_default_updates