Skip to content

Disable log scale when value is within 0.1 of zero for Histograms#13496

Open
eilskra wants to merge 1 commit intoequinor:mainfrom
eilskra:log-scale-fix
Open

Disable log scale when value is within 0.1 of zero for Histograms#13496
eilskra wants to merge 1 commit intoequinor:mainfrom
eilskra:log-scale-fix

Conversation

@eilskra
Copy link
Copy Markdown
Contributor

@eilskra eilskra commented May 6, 2026

Issue
Resolves #12527

Approach
The histogram expands the range by ±0.1 when min equals max. If the original minimum is a small positive value (e.g. 0.07), this adjustment produces a negative lower bin edge, which breaks the log-scale.

The negative_values_in_data guard now uses < 0.11 instead of ≤ 0 so that any value close enough to zero to become non-positive or 0 after the ±0.1 expansion also disable the log-scale button.

Removed +- 0.5 as this is condition won't be met since if min == max, then +- 0.1 prior to _histogramLogBins

  • 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 the release-notes:bug-fix Automatically categorise as bug fix in release notes label May 6, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.35%. Comparing base (beb9d13) to head (93b6afa).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13496      +/-   ##
==========================================
- Coverage   90.00%   85.35%   -4.65%     
==========================================
  Files         460      460              
  Lines       32332    32329       -3     
==========================================
- Hits        29101    27595    -1506     
- Misses       3231     4734    +1503     
Flag Coverage Δ
cli-tests 37.23% <0.00%> (+<0.01%) ⬆️
fuzz 44.06% <0.00%> (+<0.01%) ⬆️
gui-tests ?
performance-and-unit-tests 78.09% <100.00%> (-0.01%) ⬇️
test 45.63% <0.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
src/ert/gui/tools/plot/plot_window.py 75.28% <100.00%> (-11.24%) ⬇️
src/ert/gui/tools/plot/plottery/plots/histogram.py 96.46% <ø> (+1.63%) ⬆️

... and 65 files with indirect coverage changes

@andreas-el
Copy link
Copy Markdown
Contributor

Needs a backport to version-21.1

Comment thread src/ert/gui/tools/plot/plot_window.py Outdated
Comment on lines +422 to +425
# Use 0.11 instead of 0 because the histogram
# expands the range by ±0.1 when min == max,
# which would make a value of 0.1 become a negative bin edge.
if not numeric.empty and numeric.le(0.11).any().any():
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.

Is it possible to make this magic number a const and encapsulate some of the information in the comments in its name, if not you can also add a comment over/under the const for further explanation maybe?

The histogram expands the range by ±0.1 when min equals
max. If the original minimum is a small positive value (e.g. 0.07),
this adjustment produces a negative lower bin edge, which breaks
the log-scale.

The `negative_values_in_data` guard now uses `≤ 0.11` instead of
`≤ 0` so that any value close enough to zero to become non-positive
or 0 after the ±0.1 expansion also disable the log-scale button.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes:bug-fix Automatically categorise as bug fix in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in histogram plotter

4 participants