Skip to content

Use matplotlib method for bin creation for histogram - #13961

Closed
eilskra wants to merge 1 commit into
equinor:mainfrom
eilskra:histogram-bin-fix
Closed

Use matplotlib method for bin creation for histogram#13961
eilskra wants to merge 1 commit into
equinor:mainfrom
eilskra:histogram-bin-fix

Conversation

@eilskra

@eilskra eilskra commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Issue
Resolves #13958

Approach
Short description of the approach

(Screenshot of new behavior in GUI if applicable)

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'just rapid-tests')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Add backport label to latest release (format: 'backport release-branch-name')

@eilskra eilskra added this to SCOUT Jul 7, 2026
@eilskra eilskra moved this to Ready for Review in SCOUT Jul 7, 2026
@eilskra
eilskra requested a review from berland July 7, 2026 14:27
@eilskra

eilskra commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

From visual tests it seems like it should be correct. Would love input on this @berland

@eilskra
eilskra force-pushed the histogram-bin-fix branch from 41b0dfc to 274ee22 Compare July 8, 2026 07:25
@codecov-commenter

codecov-commenter commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.38%. Comparing base (64bb156) to head (edddc2f).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13961      +/-   ##
==========================================
+ Coverage   91.34%   91.38%   +0.03%     
==========================================
  Files         477      482       +5     
  Lines       34062    34180     +118     
==========================================
+ Hits        31115    31236     +121     
+ Misses       2947     2944       -3     
Flag Coverage Δ
cli-tests 36.03% <0.00%> (+0.06%) ⬆️
fuzz 43.63% <12.50%> (+0.10%) ⬆️
gui-tests 59.30% <62.50%> (+0.09%) ⬆️
performance-and-unit-tests 79.43% <100.00%> (+0.05%) ⬆️
test 46.12% <12.50%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/ert/gui/plotting/ert_plots/histogram.py 96.11% <100.00%> (+1.07%) ⬆️

... and 17 files with indirect coverage changes

@eilskra
eilskra force-pushed the histogram-bin-fix branch from 274ee22 to 4c559c6 Compare July 8, 2026 07:41

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Think the initial is wrong

@codspeed-hq

codspeed-hq Bot commented Jul 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing eilskra:histogram-bin-fix (edddc2f) with main (2a34262)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates ERT’s GUI histogram plotting to use Matplotlib/NumPy’s built-in bin selection (bins="sqrt") rather than computing a single bin count shared across ensembles, addressing the reported issue where an ensemble’s histogram changed when other ensembles were toggled.

Changes:

  • Remove global bin_count calculation based on the maximum ensemble size and delegate bin selection to Matplotlib (bins="sqrt").
  • Rework log-scale bin edge generation using np.histogram_bin_edges on log-transformed values, and remove the custom _histogramLogBins helper.
  • Update unit test expectations to match the new _plotHistogram call signature.

Reviewed changes

Copilot reviewed 2 out of 7 changed files in this pull request and generated 2 comments.

File Description
src/ert/gui/plotting/ert_plots/histogram.py Switch histogram bin creation to Matplotlib/NumPy’s "sqrt" rule; remove shared bin-count logic and the custom log-binning helper.
tests/ert/unit_tests/gui/plottery/test_histogram.py Adjust test mock call expectations after removing the bin_count argument.

Comment thread src/ert/gui/plotting/ert_plots/histogram.py
Comment on lines 108 to 112
mock_plot_histogram.assert_called_once_with(
ANY,
ANY,
ANY,
ANY,
use_log_scale=ANY,
@berland

berland commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Looking at the image diff for e.g. docs/ert/getting_started/configuration/poly_new/with_observations/coeff_b.png it is clear that the bin sizes / bin count is changed for iter-1, even though I cannot determine that from the code that it should have done so. This obscures visualization of what the bug entailed in this PR.

I wonder if we should ensure we fully understand what was wrong with the original code. Maybe by having a branch where both ways of computing bin edges are performed and printed to the terminal for qc, maybe also along with the data. Even better if the we could extract the old bin-making code to a function and prove it is wrong with a regression test, then fix it.

@eilskra
eilskra force-pushed the histogram-bin-fix branch from 4c559c6 to a2c0330 Compare July 8, 2026 10:07
Ensure correct count and fixes error
that displayed faulty counts, when plotting multiple ensembles
@eilskra
eilskra force-pushed the histogram-bin-fix branch from a2c0330 to edddc2f Compare July 8, 2026 10:08
@ertomatic

Copy link
Copy Markdown
Collaborator

Screenshots differ from baselines. A baseline update PR has been prepared: equinor/ert-testdata#44

ertomatic pushed a commit to equinor/ert-testdata that referenced this pull request Jul 8, 2026
@eilskra eilskra closed this Jul 8, 2026
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in SCOUT Jul 8, 2026
@eilskra
eilskra deleted the histogram-bin-fix branch July 8, 2026 13:20
@eilskra eilskra mentioned this pull request Jul 13, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Histogram bins display wrong count when plotting multiple ensembles

5 participants