FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

colormaps don't have getters for under, over, bad colors. · Issue #16075 · matplotlib/matplotlib · GitHub

Repository navigation

colormaps don't have getters for under, over, bad colors. #16075

Closed

Description

Bug report

Bug summary
colormaps don't have getters for under, over, bad colors (although the corresponding setters exist).
I am writing a function that accepts a colormap as an argument. I want to ensure that the colormap passed to the function has the same color for the "bad" and "under" conditions. The only way around this is to access "private" attributes cmap._rgba_under, cmap._rgba_bad as shown below.

Code for reproduction

cmap = plt.get_cmap('cividis')
cmap.set_bad('k')
cmap.set_under('k')

assert cmap._rgba_bad == cmap._rgba_under

If adding getters (for under, over, bad colors) for the colormaps sounds like a good improvement, i would be interested in submitting a PR.

Actual outcome

# If applicable, paste the console output here
#
#

Expected outcome

Matplotlib version

  • Operating system:
  • Matplotlib version:
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:

Activity

  1. anntzer commented on Jan 2, 2020

    Contributor

    Actually I think the setters should not exist (see #14645)...
    I think you can do cmap(+np.inf) cmap(-np.inf) cmap(np.nan) to get the over/under/bad values, not sure if it warrants a separate API?

  2. pharshalp commented on Jan 2, 2020

    ContributorAuthor

    Thanks.

  3. MaozGelbart commented on Jan 28, 2020

    Contributor

    @anntzer perhaps it warrants a different API? The difference is distinguished when bad/under/over were not set at all. Querying the cmap for such cases will result with the default extreme colors even when these were never set by the cmap creator. With getters I expect to get the set value (if provided) or None (if these weren't set at all).

  4. jklymak commented on Jan 28, 2020

    Member

    Not sure I follow. By default you definitely want a color if the mapped value is over vmax.

  5. MaozGelbart commented on Jan 28, 2020

    Contributor

    For sure, but currently I can't tell apart if set_over was called prior to that or I'm getting the default extreme value from the colormap. So by having a get_over that returns None if set_over was never called (or the input to set_over in the case it was called), I can distinguish between the two cases. This may prove useful for manipulating colormaps.

  6. pharshalp commented on Jan 28, 2020

    ContributorAuthor

    @MaozGelbart

    import matplotlib.pyplot as plt
    import numpy as np
    
    cmap = plt.get_cmap('cividis')
    # the following will return True since set_under was not used to set "under" color
    np.allclose(cmap(0), cmap(-np.inf))  # True
    
    cmap.set_under('w')
    np.allclose(cmap(0), cmap(-np.inf))  # False
    
    # similarly for set_over ...
    
    np.allclose(cmap(255), cmap(np.inf))  # True
    cmap.set_under('k')
    np.allclose(cmap(255), cmap(np.inf))  # False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL