Skip to content

[Doc]: document how to get list of registered colormaps #26244

Closed

Description

@story645

Documentation Link

https://matplotlib.org/devdocs/users/explain/colors/colormaps.html

Problem

Getting a full list of colormaps is documented in the cmap registry call function and far as I can tell nowhere else.

https://github.com/matplotlib/matplotlib/blob/f017315dd5e56c367e43fc7458fd0ed5fd9482a2/lib/matplotlib/cm.py#L100C1-L107C1

Suggested improvement

I think documentation of how to get a full list of registered colormaps should be added to:

Activity

  1. MrZaurik commented on Jul 18, 2023

    @MrZaurik

    Like a function or what are you meaning?. Look at this

    image
    image
    image
    image
    image
    image
    image

    Actually this are the colors that you can choose for your plots. In the left side you can see the name, and next to this the colormap.

    EDIT: A couple more.

  2. oscargus commented on Jul 19, 2023

    @oscargus
    Member

    I think it means that something like the following should be added:

    To get a list of all registered colormaps, you can do::
    
        from matplotlib import colormaps
        list(colormaps)
    
  3. MrZaurik commented on Jul 19, 2023

    @MrZaurik

    Perfect. I'll be work on this.

  4. MrZaurik commented on Jul 19, 2023

    @MrZaurik

    Okay, my progress was the following, I wrote a few lines in the file colormaps.py where I create a function called listColormaps() the important thing is that according to the type of colormap it will list the available patterns.

    Now, I find it useful to declare in a global way the variables of the colormap types that exist, that is to say: Perceptually, Sequential, Sequential2, Cyclic, Qualitative, Miscellaneous. In such a way that if more patterns are developed it will be easier to extend the functionalities.

    Attached is the code

    # New function to list the actually colormaps on matplotlib
    def listColormaps(category):
        # Define a dictionary that maps each category to its corresponding list of colormaps
        colormaps_by_category = {
            'Perceptually': ['viridis', 'plasma', 'inferno', 'magma', 'cividis'],
            'Sequential': ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
                           'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
                           'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn'],
            'Sequential2': ['binary', 'gist_yarg', 'gist_gray', 'gray', 'bone',
                            'pink', 'spring', 'summer', 'autumn', 'winter', 'cool',
                            'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper'],
            'Diverging': ['PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 'RdYlBu',
                          'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic'],
            'Cyclic': ['twilight', 'twilight_shifted', 'hsv'],
            'Qualitative': ['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2',
                            'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b',
                            'tab20c'],
            'Miscellaneous': ['flag', 'prism', 'ocean', 'gist_earth', 'terrain',
                              'gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap',
                              'cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet',
                              'turbo', 'nipy_spectral', 'gist_ncar']
        }
    
        # Return the list of colormaps for the given category, or an empty list if the category is not found
        return colormaps_by_category.get(category, [])
  5. tacaswell commented on Jul 20, 2023

    @tacaswell
    Member

    In https://matplotlib.org/stable/api/cm_api.html#matplotlib.cm.ColormapRegistry it is clearly marked as a subsclass of a Mapping and say

    Read access uses a dict-like interface mapping names to Colormaps:

    I think it is reasonable to expect users to infer that list(my_mapping) gets you all of the keys in the mapping.

    I think at most we need a note in explain/colors/colormaps.html to the same effect.

  6. added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Sep 10, 2023
  7. github-actions commented on Sep 10, 2023

    @github-actions

    Good first issue - notes for new contributors

    This issue is suited to new contributors because it does not require understanding of the Matplotlib internals. To get started, please see our contributing guide.

    We do not assign issues. Check the Development section in the sidebar for linked pull requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please collaborate on the work by reviewing it rather than duplicating it in a competing PR.

    If something is unclear, please reach out on any of our communication channels.

  8. story645 commented on Sep 10, 2023

    @story645
    MemberAuthor

    Flagging this as a good first issue because the solution is add what @oscargus wrote in #26244 (comment) in the locations described in #26244 (comment)

  9. added 2 commits that reference this issue on Oct 17, 2023
  10. added a commit that references this issue on Oct 17, 2023
  11. added this to the v3.8.1 milestone on Oct 17, 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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions