Skip to content

Add plot.max_subplots check before calling create_plotting_grid #425

Merged
OriolAbril merged 4 commits intoarviz-devs:mainfrom
Sakshee-D:max-subplots-clean
Feb 12, 2026
Merged

Add plot.max_subplots check before calling create_plotting_grid #425
OriolAbril merged 4 commits intoarviz-devs:mainfrom
Sakshee-D:max-subplots-clean

Conversation

@Sakshee-D
Copy link
Contributor

Description

Addresses issue #354
This PR enforces the plot.max_subplots rcParam in arviz-plots by raising an error when the requested number of subplots exceeds the limit.
The check is applied before creating the plot grid, following discussion in #354.

Key Implementation Details

Checks rcParams["plot.max_subplots"] before calling create_plotting_grid.
Raises a clear ValueError when the limit is exceeded.

Applies consistently in:

  • PlotCollection.wrap
  • PlotCollection.grid
  • plot_matrix._generate_viz_dt

@read-the-docs-community
Copy link

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

Documentation build overview

📚 arviz-plots | 🛠️ Build #31387599 | 📁 Comparing e13cccf against latest (23d4323)


🔍 Preview build

Show files changed (69 files in total): 📝 69 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
_modules/arviz_plots/plot_collection.html 📝 modified
_modules/arviz_plots/plot_matrix.html 📝 modified
api/generated/arviz_plots.PlotCollection.generate_aes_dt.html 📝 modified
api/generated/arviz_plots.PlotCollection.grid.html 📝 modified
api/generated/arviz_plots.PlotCollection.html 📝 modified
api/generated/arviz_plots.PlotCollection.wrap.html 📝 modified
api/generated/arviz_plots.PlotMatrix.html 📝 modified
api/backend/generated/arviz_plots.backend.bokeh.create_plotting_grid.html 📝 modified
api/backend/generated/arviz_plots.backend.matplotlib.create_plotting_grid.html 📝 modified
api/backend/generated/arviz_plots.backend.plotly.create_plotting_grid.html 📝 modified
_modules/arviz_plots/backend/bokeh/core.html 📝 modified
_modules/arviz_plots/backend/matplotlib/core.html 📝 modified
_modules/arviz_plots/backend/none/core.html 📝 modified
_modules/arviz_plots/backend/plotly/core.html 📝 modified

@Sakshee-D
Copy link
Contributor Author

I ran into CI failures in test_plot_matrix.py after enforcing plot.max_subplots. The test fails because they create full N×N grids ( 9×9) to test so they now exceed the default limit. I’m thinking of disabling plot.max_subplots locally in test_plot_matrix.py by a small fixture. Does that sound reasonable?

@OriolAbril
Copy link
Member

You can use https://python.arviz.org/projects/base/en/latest/api/generated/arviz_base.rc_context.html in the problematic tests.

With PlotMatrix max_subplots is a bit tricky because we might only populate the lower triangle (not the upper one or the diagonal) so the count is off, but there is the potential to draw on all generated plots so I think it is perfectly fine to keep this behaviour

@codecov-commenter
Copy link

codecov-commenter commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.23%. Comparing base (1c1641d) to head (e13cccf).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/arviz_plots/plot_collection.py 80.00% 2 Missing ⚠️
src/arviz_plots/plot_matrix.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #425      +/-   ##
==========================================
- Coverage   85.38%   85.23%   -0.16%     
==========================================
  Files          59       59              
  Lines        6883     6934      +51     
==========================================
+ Hits         5877     5910      +33     
- Misses       1006     1024      +18     

☔ 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.

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.

minor formatting comment, it is basically ready to merge

assert not missing_coord_names, list(pc.viz["plot"].coords)
assert pc.viz["plot"].sizes == {"row_index": 9, "col_index": 9}
with rc_context({"plot.max_subplots": None}):
pc = PlotMatrix(dataset, ["__variable__", "hierarchy", "group"], backend="none")
Copy link
Member

Choose a reason for hiding this comment

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

only the initialization of the PlotMatrix class needs to be inside the context, I would keep everything else outside the context

@Sakshee-D
Copy link
Contributor Author

I have limited the rc_context scope to only the PlotMatrix initialization as suggested.

@OriolAbril OriolAbril merged commit f79e625 into arviz-devs:main Feb 12, 2026
4 checks passed
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.

3 participants