Skip to content

Adding new plotting functionality to plot_ridge#420

Open
NeerjaKasture wants to merge 19 commits intoarviz-devs:mainfrom
NeerjaKasture:new-branch
Open

Adding new plotting functionality to plot_ridge#420
NeerjaKasture wants to merge 19 commits intoarviz-devs:mainfrom
NeerjaKasture:new-branch

Conversation

@NeerjaKasture
Copy link
Contributor

@NeerjaKasture NeerjaKasture commented Feb 1, 2026

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 a kind argument to the function call, and specifying the kind of plotting functionality for the kind of distribution.

Usage example:

from arviz_plots import plot_ridge, style
from arviz_base import load_arviz_data
import arviz as az
import matplotlib.pyplot as plt
style.use("arviz-variat")
non_centered = load_arviz_data('non_centered_eight')
pc = plot_ridge(
    non_centered,
    var_names=["theta", "mu", "theta_t", "tau"],
    aes={"color": ["__variable__"]},
    figure_kwargs={"width_ratios": [1, 2], "layout": "none"},
    aes_by_visuals={"labels": ["color"]},
    shade_label="school",
    kind = "hist",
)
plt.savefig("hist_ridge_plot.png")

Plots:

ECDF:

image

Histogram:

image

Quantile dot plot:

image

Copilot AI review requested due to automatic review settings February 1, 2026 21:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kind argument to plot_ridge ("kde", "ecdf", "hist", "qds") and route to the corresponding azstats methods (kde, histogram, ecdf, qds), including ridge-height normalization and appropriate edge/face visuals (line, fill, histogram bars, scatter).
  • Adjust the intermediate hist visual to treat the y aesthetic as a vertical offset (bottom) and update the matplotlib backend hist implementation to support an explicit bottom series when constructing filled histograms.
  • Wire histogram and qds visuals into the ridge plotting pipeline using hist and scatter_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-commenter
Copy link

codecov-commenter commented Feb 1, 2026

Codecov Report

❌ Patch coverage is 56.52174% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.17%. Comparing base (e31a34d) to head (b3c6727).

Files with missing lines Patch % Lines
src/arviz_plots/plots/ridge_plot.py 53.65% 19 Missing ⚠️
src/arviz_plots/backend/matplotlib/core.py 50.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@read-the-docs-community
Copy link

read-the-docs-community bot commented Feb 1, 2026

Documentation build overview

📚 arviz-plots | 🛠️ Build #31258764 | 📁 Comparing b3c6727 against latest (e31a34d)


🔍 Preview build

Show files changed (106 files in total): 📝 106 modified | ➕ 0 added | ➖ 0 deleted
File Status
gallery/add_reference_bands.html 📝 modified
gallery/add_reference_lines.html 📝 modified
gallery/combine_plots.html 📝 modified
gallery/plot_autocorr.html 📝 modified
gallery/plot_bf.html 📝 modified
gallery/plot_compare.html 📝 modified
gallery/plot_convergence_dist.html 📝 modified
gallery/plot_dgof.html 📝 modified
gallery/plot_dgof_dist.html 📝 modified
gallery/plot_dist_ecdf.html 📝 modified
gallery/plot_dist_hist.html 📝 modified
gallery/plot_dist_kde.html 📝 modified
gallery/plot_dist_models.html 📝 modified
gallery/plot_dist_qds.html 📝 modified
gallery/plot_ecdf_coverage.html 📝 modified
gallery/plot_ecdf_pit.html 📝 modified
gallery/plot_energy.html 📝 modified
gallery/plot_ess_evolution.html 📝 modified
gallery/plot_ess_local.html 📝 modified
gallery/plot_ess_models.html 📝 modified
gallery/plot_ess_quantile.html 📝 modified
gallery/plot_forest.html 📝 modified
gallery/plot_forest_ess.html 📝 modified
gallery/plot_forest_models.html 📝 modified
gallery/plot_forest_pp_obs.html 📝 modified
gallery/plot_forest_shade.html 📝 modified
gallery/plot_khat.html 📝 modified
gallery/plot_khat_aesthetics.html 📝 modified
gallery/plot_khat_facet_cols.html 📝 modified
gallery/plot_khat_facet_grid.html 📝 modified
gallery/plot_loo_pit.html 📝 modified
gallery/plot_mcse.html 📝 modified
gallery/plot_pair.html 📝 modified
gallery/plot_pair_distribution.html 📝 modified
gallery/plot_pair_focus.html 📝 modified
gallery/plot_pair_focus_distribution.html 📝 modified
gallery/plot_parallel.html 📝 modified
gallery/plot_pava_calibration.html 📝 modified
gallery/plot_ppc_censored.html 📝 modified
gallery/plot_ppc_coverage.html 📝 modified
gallery/plot_ppc_dist.html 📝 modified
gallery/plot_ppc_interval.html 📝 modified
gallery/plot_ppc_pava_residuals.html 📝 modified
gallery/plot_ppc_pit.html 📝 modified
gallery/plot_ppc_rootogram.html 📝 modified
gallery/plot_ppc_tstat.html 📝 modified
gallery/plot_prior_posterior.html 📝 modified
gallery/plot_psense.html 📝 modified
gallery/plot_psense_quantities.html 📝 modified
gallery/plot_rank.html 📝 modified
gallery/plot_rank_dist.html 📝 modified
gallery/plot_ridge.html 📝 modified
gallery/plot_ridge_multiple.html 📝 modified
gallery/plot_trace.html 📝 modified
gallery/plot_trace_dist.html 📝 modified
tutorials/compose_own_plot.html 📝 modified
tutorials/intro_to_plotcollection.html 📝 modified
tutorials/plots_intro.html 📝 modified
_modules/arviz_plots/visuals.html 📝 modified
api/generated/arviz_plots.PlotCollection.generate_aes_dt.html 📝 modified
api/generated/arviz_plots.PlotCollection.get_aes_as_dataset.html 📝 modified
api/generated/arviz_plots.PlotCollection.grid.html 📝 modified
api/generated/arviz_plots.PlotCollection.html 📝 modified
api/generated/arviz_plots.PlotCollection.map.html 📝 modified
api/generated/arviz_plots.PlotCollection.update_aes_from_dataset.html 📝 modified
api/generated/arviz_plots.PlotCollection.wrap.html 📝 modified
api/generated/arviz_plots.PlotMatrix.html 📝 modified
api/generated/arviz_plots.PlotMatrix.map.html 📝 modified
api/generated/arviz_plots.PlotMatrix.map_col.html 📝 modified
api/generated/arviz_plots.PlotMatrix.map_row.html 📝 modified
api/generated/arviz_plots.PlotMatrix.map_triangle.html 📝 modified
api/generated/arviz_plots.combine_plots.html 📝 modified
api/generated/arviz_plots.plot_autocorr.html 📝 modified
api/generated/arviz_plots.plot_bf.html 📝 modified
api/generated/arviz_plots.plot_convergence_dist.html 📝 modified
api/generated/arviz_plots.plot_dist.html 📝 modified
api/generated/arviz_plots.plot_ecdf_pit.html 📝 modified
api/generated/arviz_plots.plot_energy.html 📝 modified
api/generated/arviz_plots.plot_ess.html 📝 modified
api/generated/arviz_plots.plot_ess_evolution.html 📝 modified
api/generated/arviz_plots.plot_forest.html 📝 modified
api/generated/arviz_plots.plot_lm.html 📝 modified
api/generated/arviz_plots.plot_loo_pit.html 📝 modified
api/generated/arviz_plots.plot_mcse.html 📝 modified
api/generated/arviz_plots.plot_pair.html 📝 modified
api/generated/arviz_plots.plot_pair_focus.html 📝 modified
api/generated/arviz_plots.plot_parallel.html 📝 modified
api/generated/arviz_plots.plot_ppc_censored.html 📝 modified
api/generated/arviz_plots.plot_ppc_dist.html 📝 modified
api/generated/arviz_plots.plot_ppc_interval.html 📝 modified
api/generated/arviz_plots.plot_ppc_pava.html 📝 modified
api/generated/arviz_plots.plot_ppc_pava_residuals.html 📝 modified
api/generated/arviz_plots.plot_ppc_pit.html 📝 modified
api/generated/arviz_plots.plot_ppc_rootogram.html 📝 modified
api/generated/arviz_plots.plot_ppc_tstat.html 📝 modified
api/generated/arviz_plots.plot_prior_posterior.html 📝 modified
api/generated/arviz_plots.plot_psense_dist.html 📝 modified
api/generated/arviz_plots.plot_psense_quantities.html 📝 modified
api/generated/arviz_plots.plot_rank.html 📝 modified
api/generated/arviz_plots.plot_rank_dist.html 📝 modified
api/generated/arviz_plots.plot_ridge.html 📝 modified
api/generated/arviz_plots.plot_trace.html 📝 modified
api/generated/arviz_plots.plot_trace_dist.html 📝 modified
api/generated/arviz_plots.visuals.multiple_lines.html 📝 modified
_modules/arviz_plots/plots/ridge_plot.html 📝 modified
_modules/arviz_plots/backend/matplotlib/core.html 📝 modified

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@aloctavodia
Copy link
Contributor

@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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a check before this

)
if kind == "hist":
plot_collection.map(
hist,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hist,
step_hist,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to plot a step histogram? In that case, I will make relevant changes for step_hist function instead of hist

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks.

coords={"column": "ridge"},
**face_kwargs,
)
elif kind == "qds":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch and the next branch can be unified

NeerjaKasture and others added 9 commits February 3, 2026 22:46
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>
Copy link
Contributor

@aloctavodia aloctavodia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to update the tests.

elif kind == "dot":
density = distribution.azstats.qds(dim=edge_dims, **stats.get("dist", {}))
else:
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has already been checked

coords={"column": "ridge"},
**face_kwargs,
)
if kind in ["hist", "qds"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if kind in ["hist", "qds"]:
if kind == "hist":

I was talking of the other branch, not this one.

Copy link
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the value for kind is dot, qds is the function in arviz-stats (similarly, kind is hist but arviz-stats function is histogram)

@OriolAbril OriolAbril changed the title Adding new plotting functionality to plot_ridge #297 Adding new plotting functionality to plot_ridge Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generalize plot_ridge

4 participants