Skip to content

Don't try to use the colorbar formatter to format RGBA data. #14069

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
Apr 29, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 28, 2019

A colorbar doesn't make much sense for RGBA data, but matplotlib does
allow one to be constructed; when formatting the cursor data for a RGBA
image we must be careful to not use the colorbar formatter.

Otherwise, after plt.imshow(np.random.rand(5, 5, 3)); plt.colorbar(),
when moving the mouse cursor over the image, we get

<elided>
  File "/usr/lib/python3.7/site-packages/matplotlib/ticker.py", line 604, in format_data_short
    return '%-12g' % value
  File "/usr/lib/python3.7/site-packages/numpy/ma/core.py", line 4296, in __float__
    raise TypeError("Only length-1 arrays can be converted "
TypeError: Only length-1 arrays can be converted to Python scalars

release critical as a regression from #12459.

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

A colorbar doesn't make much sense for RGBA data, but matplotlib does
allow one to be constructed; when formatting the cursor data for a RGBA
image we must be careful to not use the colorbar formatter.

Otherwise, after `plt.imshow(np.random.rand(5, 5, 3)); plt.colorbar()`,
when moving the mouse cursor over the image, we get
```
<elided>
  File "/usr/lib/python3.7/site-packages/matplotlib/ticker.py", line 604, in format_data_short
    return '%-12g' % value
  File "/usr/lib/python3.7/site-packages/numpy/ma/core.py", line 4296, in __float__
    raise TypeError("Only length-1 arrays can be converted "
TypeError: Only length-1 arrays can be converted to Python scalars
```
@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Apr 28, 2019
@anntzer anntzer added this to the v3.1.0 milestone Apr 28, 2019
@dstansby dstansby merged commit 1009c14 into matplotlib:master Apr 29, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 29, 2019
@anntzer anntzer deleted the rgba_colorbar_formatcursordata branch April 29, 2019 11:37
timhoffm added a commit that referenced this pull request Apr 29, 2019
…069-on-v3.1.x

Backport PR #14069 on branch v3.1.x (Don't try to use the colorbar formatter to format RGBA data.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants