Adding new plotting functionality to plot_ridge#420
Adding new plotting functionality to plot_ridge#420NeerjaKasture wants to merge 19 commits intoarviz-devs:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request extends plot_ridge to support multiple distribution visualizations (KDE, ECDF, histogram, and quantile-dot style) and updates the histogram plumbing so ridges can be vertically offset via the y aesthetic.
Changes:
- Add a
kindargument toplot_ridge("kde","ecdf","hist","qds") and route to the correspondingazstatsmethods (kde,histogram,ecdf,qds), including ridge-height normalization and appropriate edge/face visuals (line, fill, histogram bars, scatter). - Adjust the intermediate
histvisual to treat theyaesthetic as a vertical offset (bottom) and update the matplotlib backendhistimplementation to support an explicitbottomseries when constructing filled histograms. - Wire histogram and qds visuals into the ridge plotting pipeline using
histandscatter_xy, and add specialized face handling for qds ridges.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/arviz_plots/visuals/__init__.py |
Reworks the hist and step_hist visuals so that the y aesthetic is interpreted as a vertical baseline (bottom), enabling vertically offset histograms (e.g., in ridge plots). |
src/arviz_plots/plots/ridge_plot.py |
Introduces the kind argument to plot_ridge, adds branching for KDE/ECDF/hist/qds density computation and normalization, and maps the appropriate visuals (line_xy, hist, scatter_xy, fill_between_y) for edges and faces. |
src/arviz_plots/backend/matplotlib/core.py |
Updates the matplotlib hist backend to honor a nonzero bottom by drawing bars between bottom and bottom + y, and passes bottom explicitly into fill_between for correct vertical stacking. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #420 +/- ##
==========================================
- Coverage 85.38% 85.17% -0.21%
==========================================
Files 59 59
Lines 6883 6916 +33
==========================================
+ Hits 5877 5891 +14
- Misses 1006 1025 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@NeerjaKasture, please don't ask Copilot to review PRs. You can use this and other LLMs in your own IDE if you want. |
| density = distribution.azstats.ecdf(dim=edge_dims, **stats.get("dist", {})) | ||
| elif kind == "qds": | ||
| density = distribution.azstats.qds(dim=edge_dims, **stats.get("dist", {})) | ||
| else: |
There was a problem hiding this comment.
I added a check before this
| ) | ||
| if kind == "hist": | ||
| plot_collection.map( | ||
| hist, |
There was a problem hiding this comment.
| hist, | |
| step_hist, |
There was a problem hiding this comment.
do we want to plot a step histogram? In that case, I will make relevant changes for step_hist function instead of hist
src/arviz_plots/plots/ridge_plot.py
Outdated
| coords={"column": "ridge"}, | ||
| **face_kwargs, | ||
| ) | ||
| elif kind == "qds": |
There was a problem hiding this comment.
This branch and the next branch can be unified
Co-authored-by: Osvaldo A Martin <aloctavodia@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Osvaldo A Martin <aloctavodia@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
aloctavodia
left a comment
There was a problem hiding this comment.
Remember to update the tests.
| elif kind == "dot": | ||
| density = distribution.azstats.qds(dim=edge_dims, **stats.get("dist", {})) | ||
| else: | ||
| raise ValueError( |
There was a problem hiding this comment.
This has already been checked
| coords={"column": "ridge"}, | ||
| **face_kwargs, | ||
| ) | ||
| if kind in ["hist", "qds"]: |
There was a problem hiding this comment.
| if kind in ["hist", "qds"]: | |
| if kind == "hist": |
I was talking of the other branch, not this one.
OriolAbril
left a comment
There was a problem hiding this comment.
very quick skim, I will try to review later
| face_density = xr.concat([face_density, zeros], dim="kwarg") | ||
| if kind == "hist": | ||
| face_density = density | ||
| elif kind == "qds": |
There was a problem hiding this comment.
the value for kind is dot, qds is the function in arviz-stats (similarly, kind is hist but arviz-stats function is histogram)
Closes #297
This PR adds functionality to support plotting ECDF, Histogram and Quantile dot plot along with KDE in
ridge_plot.py. This was done by adding akindargument to the function call, and specifying the kind of plotting functionality for the kind of distribution.Usage example:
Plots:
ECDF:
Histogram:
Quantile dot plot: