Repository navigation
refactor: draw cdf and cdf-diff SBC plots with one helper, remove unused colour helpers - #2161
Conversation
sbi-dev#1951 added the cdf-diff plot type as copies of the cdf curve and band helpers, and as a second set of branches in `_sbc_rank_plot`. The copies differ only in subtracting the uniform CDF, the y range and label, and a zero line. Give `_plot_ranks_as_cdf` and `_plot_cdf_region_expected_under_uniformity` a `diff` flag and drop the copies. `plot_type` is validated before plotting, so the `else: raise` branches could not be reached. The plots don't change: 576 renders over plot types, rank sets, subplot layouts, bin counts, numbers of posterior samples and rank distributions are pixel-identical to main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They came over with the plotting code in 2020 and nothing calls them, in sbi or, according to a GitHub code search, elsewhere. `sbi.utils` does not re-export them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2161 +/- ##
==========================================
+ Coverage 90.69% 90.72% +0.03%
==========================================
Files 142 142
Lines 14855 14830 -25
==========================================
- Hits 13472 13454 -18
+ Misses 1383 1376 -7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
It sat inside the parameter loop, at the end of the histogram branch, but describes the code that runs after the loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @dgedon, nice cleanup, and the pixel comparison against While reviewing I found two problems in the SBC plots that were in
I'll fix both in a follow-up PR and ask you for the review. |
Summary
Two cleanups in the plotting code, with no change to what is drawn.
1. One helper for the
cdfandcdf-diffSBC plots. #1951 added thecdf-diffplot type as copies of thecdfcurve and band helpers (_plot_ranks_as_cdf_diff,_plot_cdf_diff_region_expected_under_uniformity), plus a second set of branches in_sbc_rank_plot, in both the subplot and the single-axis layout. The copies differ only in subtracting the uniform CDF, the y range and label, and a dashed zero line. #2119 already shares the band and the x positions (_uniform_cdf_band,_cdf_x).This PR gives
_plot_ranks_as_cdfand_plot_cdf_region_expected_under_uniformityadiffflag and removes the copies._sbc_rank_plotnow has one branch for both plot types.plot_typeis validated before plotting, so the twoelse: raise ValueErrorbranches could not be reached and are removed too. #1951's review noted that the "general refactoring" part of #1734 was still open, because the docstrings of the CDF and histogram helpers didn't match their arguments. Those docstrings already match on main; this PR removes the duplication #1951 left in the CDF helpers.2. Remove
hex2rgbandrgb2hexfromsbi/utils/plotting_helpers.py. They came over with the plotting code in 2020, nothing in sbi calls them,sbi.utilsdoesn't re-export them, and a GitHub code search finds no users.Evidence
The plots don't change. I rendered
sbc_rank_plotfor every combination of:cdf,cdf-diff,hist),params_in_subplotson and off,num_bins(default, 1, 7, 30),num_posterior_samples(10, 1000),show_uniform_regionon and off,All 576 images are pixel-identical to
main. As a control, scaling the uniform reference by 0.99 changes 384 of them, all thecdfandcdf-diffcases.tests/plot_test.pyandtests/sbc_test.py::test_sbc_plottingpass (564 passed, 9 expected failures), including #2119's tests of the drawn SBC curves and bands.pyright sbiandpre-commiton the changed files pass. I did not run the full test suite locally.Merge Danger
Door: two-way.
Blast Radius:
sbc_rank_plotkeeps its signature, and what it draws doesn't change.hex2rgbandrgb2hexcan no longer be imported fromsbi.utils.plotting_helpers.Related: independent of #2160, which edits other parts of
plot.py; the two merge without conflicts. #2154 edits other lines ofsbi/utils/plotting_helpers.py.I used Claude Code for the analysis, the implementation and the checks.
🤖 Generated with Claude Code