Skip to content

[ENH] Unit support for ScalarMappables #7383

Open

Description

@story645

In #6934 (categorical colormapping), I'm trying to add support for imshow visualizing arrays of strings ('cause strings are data...) and then creating the associated colorbar and eventually a legend.
What I've run headlong into (and has created spaghetti code) is that imshow doesn't support unit conversions, which sort of makes sense as norms dictate how things should be colored but it also creates this weird circular dependencies of sorts on how the data gets coded when it's time to also set up the colorbars 'cause of how ticks/locators are done there (still super confused on all that).

I'd really like to add that sort of "unit" knowledge to imshow (or its underlying object).

The plan is to:

  1. extend the AxisInfo object in units.py with the default norm, colormap, and cbar locators/formatters or to create another object SMInfo or something that stores that info.

Edit: Can't decide the name 'cause this is an issue for anything that takes a colorbar, which is both the AxesImage objects and stuff like scatter.
2) use units in the underlying imshow code in the manner it's currently used in the plot code.

I think this could also maybe be used to later refactor the colorbar code or norms or something. And possibly codifying what's the defaults for floats and ints and the like-basically unit becomes a stylesheet of sorts for data.

Activity

  1. changed the title [-][ENH] Unit support for ScalerMappables[/-] [+][ENH] Unit support for AxesImage[/+] on Nov 3, 2016
  2. changed the title [-][ENH] Unit support for AxesImage[/-] [+][ENH] Unit support for ScalerMappables[/+] on Nov 3, 2016
  3. added this to the milestone on Nov 4, 2016
  4. kahnchana commented on Mar 31, 2017

    @kahnchana
    Contributor

    I'm trying to work on this. So I went through units.py and also pyplot.py with imshow function implementations. Is there anything special I should know before trying this? I am currently going through the colormap and normalization documentation as well.

  5. story645 commented on Mar 31, 2017

    @story645
    MemberAuthor

    Look through the normalization, colormap, and colorbar code.

  6. kahnchana commented on Mar 31, 2017

    @kahnchana
    Contributor

    Should I fork the matplotlib code or the code you've worked on when doing this?

  7. story645 commented on Mar 31, 2017

    @story645
    MemberAuthor

    matplotlib

  8. modified the milestones: , on Sep 24, 2017
  9. story645 commented on Feb 4, 2018

    @story645
    MemberAuthor

    @jklymak I dunno if this should be thought through as part of a units MEP or built on top of one, but mostly fyi.

  10. jklymak commented on Feb 4, 2018

    @jklymak
    Member

    Cool. OTOH I personally think this should just be its own method versus something that gets tacked into imshow, so I wouldn't write that part of the MEP 😉 But thats just my vote....

  11. story645 commented on Feb 4, 2018

    @story645
    MemberAuthor

    it's not about imshow but about all scalermappable. A fairly popular request is to natively get categories working in scatter plots (no loops) and that would kind of come for free with any solution that's generalizable to scalermappables. It can sort of be solved just via a categorical norm, but that doesn't fit with the idea of it being a magically handled type. (Also part of this would be to hook in legends)

  12. 13 remaining items

  13. dopplershift commented on Mar 27, 2018

    @dopplershift
    Contributor

    I kind of like the idea of a CategoryNorm...but would that get the automated labels for the colorbar?

  14. story645 commented on Mar 27, 2018

    @story645
    MemberAuthor

    So I tried doing that in #6934 and it quickly became spaghetti...

    I kind of like the idea of a CategoryNorm...but would that get the automated labels for the colorbar?

    Yeah, that's what I wonder too...and legends even more so...maybe the code is the same? CategoryNorm creates a list of labels, and I guess falls back to the cmap if there's no list of colors for legend to work on?

  15. jklymak commented on Mar 27, 2018

    @jklymak
    Member

    Automatic labels for a colorbar are pretty hard to implement anyway - I think the call would be for a legend like above? It seems writing a legend subclass would be possible as well.

  16. dopplershift commented on Mar 28, 2018

    @dopplershift
    Contributor

    Well, if the CategoryNorm had the inverse mapping, you could run the tick values back through it...

  17. story645 commented on Mar 28, 2018

    @story645
    MemberAuthor

    And then going off @jklymak 's suggestion, use something like ax.sclegend() (yes have no idea how to name this) that subclassess legend and will generate off norm and cmap info? I'm tentatively not opposed to that approach...

  18. efiring commented on Mar 28, 2018

    @efiring
    Member

    I really think the colorbar is the wrong tool for this, and a specialized legend (a separate function that calls legend, not more kwargs for the existing legend) is the appropriate tool. Similarly, I am strongly opposed to trying to pile any more functionality of this sort directly into imshow and similar functions.

  19. story645 commented on Mar 28, 2018

    @story645
    MemberAuthor

    I agree that colorbar is the wrong tool, but I tink his wouldn't actually require any new kwargs to be passed to legend since the cmap and norm can be obtained via handle or axes inspection, same as current legend.

    When thinking through this on the unit side, the implementation would probably be on the norm/cmap side of things any which way since that's probably the way to generalize it to all ScalerMappable. But what I'd want on the units side is a "default norm" of sorts, like the locator and formatter. So if people are using categorical data, they're also using categorical norm unless they explicitly change it. That would give me the "norming for free" and probably wouldn't require any changes to AxesImage or the like.

  20. efiring commented on Mar 28, 2018

    @efiring
    Member

    I presume the norm would map a list of strings to consecutive integers starting at zero, so that these integers would directly index into a discrete colormap. The user would have to choose a map with a suitable (presumably small) number of well-distinguished colors--something like one of the color sets used for plotting lines. There would be no concept of "over" and "under"; strings not in the list supplied to the norm would be in the "bad" category, for which a color (or full transparency) can be specified in the colormap.

  21. story645 commented on Jul 12, 2019

    @story645
    MemberAuthor

    So thinking through this even more, the most straightforward way to do this at first would probably be to attach a convertor to NoNorm

  22. jklymak commented on Jul 31, 2020

    @jklymak
    Member

    Carrying on the discussion in #18139: it seems to me the sticking point is still that I've never seen someone store a 2-D array of strings. If I have seen two-D arrays of "categories" they have been integer arrays with appropriate metadata stating the integer-category mapping.

    Are 2-D arrays of string objects something anyone has actually wanted to work with? It seems working this up as a standalone package would help show its utility for the core library. I don't see what's preventing a standalone package that is at least of proof of concept.

  23. github-actions commented on Apr 2, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  24. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions