Skip to content

Commit

Permalink
Fix legend labels in plot_ppc to reflect prior or posterior. (#1967)
Browse files Browse the repository at this point in the history
* Fix legend labels in plot_ppc to reflect prior or posterior.

Legend labels were not tracking the selected group. In many instances
they were hardcoded to "Posterior ...".

* Appease black with formatting fix.

* Update CHANGELOG
  • Loading branch information
jedludlow authored Jan 20, 2022
1 parent a67d81c commit 9d07469
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Bokeh 3 compatibility. ([1919](https://github.com/arviz-devs/arviz/pull/1919))
* Remove manual setting of 2d KDE limits ([1939](https://github.com/arviz-devs/arviz/pull/1939))
* Pin to bokeh<3 version ([1954](https://github.com/arviz-devs/arviz/pull/1954))
* Fix legend labels in plot_ppc to reflect prior or posterior. ([1967](https://github.com/arviz-devs/arviz/pull/1967))

### Deprecation

Expand Down
10 changes: 5 additions & 5 deletions arviz/plots/backends/matplotlib/ppcplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ def plot_ppc(
drawstyle=drawstyle,
linewidth=linewidth,
)
ax_i.plot([], color=colors[0], label="Posterior predictive")
ax_i.plot([], color=colors[0], label=f"{group.capitalize()} predictive")
if mean:
ax_i.plot(
*_empirical_cdf(pp_vals.flatten()),
color=colors[2],
linestyle="--",
linewidth=linewidth * 1.5,
drawstyle=drawstyle,
label="Posterior predictive mean",
label=f"{group.capitalize()} predictive mean",
)
ax_i.set_yticks([0, 0.5, 1])

Expand All @@ -280,7 +280,7 @@ def plot_ppc(
"linewidth": linewidth * 1.5,
"zorder": 3,
},
label="Posterior predictive mean",
label=f"{group.capitalize()} predictive mean",
ax=ax_i,
legend=legend,
)
Expand All @@ -294,7 +294,7 @@ def plot_ppc(
hist,
color=colors[2],
linewidth=linewidth * 1.5,
label="Posterior predictive mean",
label=f"{group.capitalize()} predictive mean",
zorder=3,
linestyle="--",
drawstyle="steps-pre",
Expand Down Expand Up @@ -350,7 +350,7 @@ def plot_ppc(
alpha=alpha,
)

ax_i.plot([], color=colors[0], marker="o", label="Posterior predictive")
ax_i.plot([], color=colors[0], marker="o", label=f"{group.capitalize()} predictive")

ax_i.set_yticks([])

Expand Down

0 comments on commit 9d07469

Please sign in to comment.