Skip to content

Commit 2a201ed

Browse files
committed
#51 add label to shaded HDI + update notebook + plot outputs
1 parent 36d6e1d commit 2a201ed

File tree

6 files changed

+6450
-9008
lines changed

6 files changed

+6450
-9008
lines changed

causalpy/plot_utils.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
import arviz as az
22

33

4-
def plot_xY(x, Y, ax, plot_hdi_kwargs=dict()):
4+
def plot_xY(x, Y, ax, plot_hdi_kwargs=dict(), hdi_prob: float = 0.94) -> None:
55
"""Utility function to plot HDI intervals."""
6-
quantiles = Y.quantile(
7-
(0.025, 0.25, 0.5, 0.75, 0.975), dim=("chain", "draw")
8-
).transpose()
96

7+
Y = Y.stack(samples=["chain", "draw"]).T
108
az.plot_hdi(
119
x,
12-
hdi_data=quantiles.sel(quantile=[0.025, 0.975]),
13-
fill_kwargs={"alpha": 0.25},
10+
Y,
11+
hdi_prob=hdi_prob,
12+
fill_kwargs={"alpha": 0.25, "label": f"{hdi_prob*100}% HDI"},
1413
smooth=False,
1514
ax=ax,
1615
**plot_hdi_kwargs,
1716
)
18-
az.plot_hdi(
19-
x,
20-
hdi_data=quantiles.sel(quantile=[0.25, 0.75]),
21-
fill_kwargs={"alpha": 0.5},
22-
smooth=False,
23-
ax=ax,
24-
**plot_hdi_kwargs,
25-
)
26-
ax.plot(x, quantiles.sel(quantile=0.5), color="k")
17+
ax.plot(x, Y.mean(dim="samples"), color="k", label="Posterior mean")

docs/notebooks/pymc_demos.ipynb

Lines changed: 140 additions & 33 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)