Skip to content

Cast vmin/vmax to floats before nonsingular-expanding them. #16344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 27, 2020

Nonsingular-expansion is fundamentally about adding small floats to
separate vmin/vmax so casting to float is normal; this avoids running
into plain wrong autoscales with

im = imshow([[np.int16(-20000), np.int16(20000)]])
colorbar()
print(im.norm.vmin, im.norm.vmax)

20000
(note the extra expansion above 20000 and below -20000, which is not normally not present)
or

im = imshow([[np.int16(-32768), np.int16(0)]])
colorbar()
print(im.norm.vmin, im.norm.vmax)

32768
(note the completely wrong colormapping)

(The bug is present as far back as 2.2.0. This would be somewhat nice to have in 3.2, but I'm not insisting on it either.)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@codecov
Copy link

codecov bot commented Jan 27, 2020

Codecov Report

Merging #16344 into master will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16344      +/-   ##
==========================================
- Coverage   80.86%   80.79%   -0.08%     
==========================================
  Files         307      307              
  Lines       75689    75696       +7     
  Branches     9679     9679              
==========================================
- Hits        61208    61159      -49     
- Misses      11944    11995      +51     
- Partials     2537     2542       +5     
Impacted Files Coverage Δ
lib/matplotlib/backends/backend_macosx.py 4.39% <0.00%> (-36.27%) ⬇️
lib/matplotlib/backends/qt_compat.py 48.42% <0.00%> (-3.16%) ⬇️
lib/matplotlib/backends/backend_qt5.py 56.16% <0.00%> (-1.17%) ⬇️
lib/matplotlib/backends/backend_wx.py 49.11% <0.00%> (-0.84%) ⬇️
lib/matplotlib/font_manager.py 74.53% <0.00%> (-0.75%) ⬇️
lib/matplotlib/cbook/__init__.py 77.11% <0.00%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58c6698...ddf2c1b. Read the comment docs.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 27, 2020

Not sure why codecov posted a comment on this PR :/

Nonsingular-expansion is fundamentally about adding small floats to
separate vmin/vmax so casting to float is normal; this avoids running
into plain wrong autoscales with
```
im = imshow([[np.int16(-20000), np.int16(20000)]])
colorbar()
print(im.norm.vmin, im.norm.vmax)
```
or
```
im = imshow([[np.int16(-32768), np.int16(0)]])
colorbar()
print(im.norm.vmin, im.norm.vmax)
```

(The bug is present as far back as 2.2.0.)
@tacaswell tacaswell added this to the v3.2.0 milestone Jan 28, 2020
@tacaswell tacaswell merged commit 18ed621 into matplotlib:master Jan 29, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 29, 2020
timhoffm added a commit that referenced this pull request Jan 29, 2020
…344-on-v3.2.x

Backport PR #16344 on branch v3.2.x (Cast vmin/vmax to floats before nonsingular-expanding them.)
@anntzer anntzer deleted the colorbar-int branch January 29, 2020 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants