Skip to content

colormap generalization #18809

Closed as not planned
Closed as not planned

Description

@rwijtvliet

Problem

The current implementation of colormaps maps a 1D float interval onto a 1D color spectrum. Meaning, I can use a colormap to find the color that 'matches' a single float value.

Sometimes, however, I'd like to get the color that matches a pair or triplet of float values.

A use case: coloring locations on a city map, where the color for each location is calculated from 2 values: the time needed to get there by car, and the time needed to get there by public transport. Or, from 3 values, if the time needed to get there by bike is also included. In that case, the color could be picked from a color triangle like this one.

Proposed Solution

I ran into this problem and created a solution here: https://github.com/rwijtvliet/interpol.

Now, please note I've only created this for myself and probably needs a lot of work to be able to get merged into matplotlib. For example, there is no unit tests whatsoever.

Proposed Way Forward

  1. A core developer has a look a the linked project to check out, what I mean, and to judge if this is something the matplotlib package would actually benefit from including. (The examples at the ends of the sections ColorMap2 and ColorMap3 in the readme are the best places to start to get an idea of what I mean.)
  2. If yes, someone probably has some suggestions regarding how to start on a PR for this feature. I'd gladly help to get this included into the project, but my coding skills are insufficient to do this without by myself.

But let's first see if this is deemed of interest. :)

Activity

  1. timhoffm commented on Oct 26, 2020

    @timhoffm
    Member

    @rwijtvliet Thanks for the proposal! I see where this is useful.

    Mapping multiple values to a color is a rather specialized application. Given the vast scope of visualization, we try to keep Matplotlib focused on core features to keep it manageable. The proposed way forward here is to create a third-party package. This also has the advantage, that you can move the development at your own pace independent of the Matplotlib release cycle.

    We'd be happy to include such a package in https://matplotlib.org/thirdpartypackages/index.html. If there's interest, there's also the possibility to host third-party repositories under the Matplotlib GitHub Project.

    If a separate project is too big, it's also possible to add code as an example. Though it seems one needs quite a bit of code, which could make the example hard to read.

  2. tacaswell commented on Oct 26, 2020

    @tacaswell
    Member

    We also had a GSOC student take a pass at this 3 years but it ended up not being merged (yet): #8738 .

    The examples in the README are pretty nifty @rwijtvliet :)

    I suggest having a look at https://github.com/NSLS-II/scientific-python-cookiecutter / https://nsls-ii.github.io/scientific-python-cookiecutter/ for how to bootstrap the code you have into a full package.

  3. ianhi commented on Oct 27, 2020

    @ianhi
    Contributor

    There's also a list of pieces of info I thought might helpful when making a 3rd party packages here: #18496

  4. rwijtvliet commented on Oct 28, 2020

    @rwijtvliet
    Author

    Hey guys, thanks for the feedback, much appreciated.

    #8738 is similar in accepting >1 float, but different in not returning a color based on the relative difference (i.e., it accepts quantities with unequal physical units). But I'm sure I can learn a lot from that code.

    I'll see what the best way to go about things is here and start with posting an example. @timhoffm, you included a link to the examples page, but I'm not immediately seeing a way to add my own example. Am I missing something?

  5. jklymak commented on Oct 28, 2020

    @jklymak
    Member

    @rwijtvliet You add an example by adding python code in examples/

  6. github-actions commented on Sep 1, 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!

  7. jklymak commented on Sep 1, 2023

    @jklymak
    Member

    This is basically #14168, so lets close this...

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions