Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Closed
2 tasks
story645 opened this issue Jul 3, 2023 · 7 comments
Closed
2 tasks

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

story645 opened this issue Jul 3, 2023 · 7 comments
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: color/color & colormaps
Milestone

Comments

@story645
Copy link
Member

story645 commented Jul 3, 2023

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:

@MrZaurik
Copy link

MrZaurik commented Jul 18, 2023

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.

@oscargus
Copy link
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)

@MrZaurik
Copy link

Perfect. I'll be work on this.

MrZaurik added a commit to MrZaurik/matplotlib that referenced this issue Jul 19, 2023
MrZaurik added a commit to MrZaurik/matplotlib that referenced this issue Jul 19, 2023
MrZaurik added a commit to MrZaurik/matplotlib that referenced this issue Jul 19, 2023
@MrZaurik
Copy link

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, [])

@tacaswell
Copy link
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.

@story645 story645 added the Good first issue Open a pull request against these issues if there are no active ones! label Sep 10, 2023
@github-actions
Copy link

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.

@story645
Copy link
Member Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: color/color & colormaps
Projects
None yet
Development

No branches or pull requests

5 participants