feat: add plot_dist for posterior density plots - #467
Open
RussellSB wants to merge 5 commits into
Open
Conversation
RussellSB
requested review from
cetagostini,
drbenvincent and
juanitorduz
as code owners
August 21, 2026 14:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
plot_dist()for posterior density plots onPathModeland the three draw-backed result objects:EffectResult,EstimandResult, andDoResult."a"), defined parameters ("indirect"), or raw posterior variables ("sigma_Y");coords=disambiguates multi-coordinate variables.plot_density()renderer inpathmc.plotting(KDE curve + translucent fill + optional dashed reference line).Issue links
Examples
Fitted mediation model (
X -> M -> Ywith a direct effect):1. Model: labeled coefficients
1.1 Plain
1.2 Reference lines at the true values
1.3 Plus custom colors
2. Model: defined parameters
3. EffectResult: path effect
4. EstimandResult: ATE
5. DoResult: interventional outcome
Design decisions
var/refnaming: generalised from the issue'svar_names/ref_valso one name works across all four entry points.coloroptional:str | list[str]on the model; a singlestron result objects.plot_dist()returnsNone(callsplt.show()internally).plot_density()is public: exported frompathmc.Questions
plot_density()public? It surfaces in the API reference and is directly usable for custom cases (comparing a posterior to a ground-truth distribution, for instance).plot_paramsargument for figure-level knobs (figsize, title, axis labels)? A future idea to extend on this method's customisation. Deferred and not blocking; happy to follow up in a later PR if there's appetite.Test plan
uv run pytest tests/test_plot_dist.py -x -vmake test-fastmake lintMade with OpenCode Go (and a moderate amount of AI nagging)