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
added a reversing section to colormap reference #23904
base: main
Are you sure you want to change the base?
Conversation
examples/color/colormap_reference.py
Outdated
| A reversed version of each of these colormaps is available by appending | ||
| ``_r`` to the name, e.g., ``viridis_r``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep this, and reference below with an anchor link.... Otherwise this looks great
examples/color/colormap_reference.py
Outdated
| # A reversed version of any colormap is available by appending ``_r`` to the | ||
| # name, for example: | ||
|
|
||
| plot_color_gradients("Reversed ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about showing viridis and viridis_r in direct comparison instead of some random maps where I have to look up the unreversed version above to see the effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Jody Klymak <jklymak@gmail.com> Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
| # Reversing a colormap | ||
| # -------------------- | ||
| # | ||
| # A colormap can be reversed by appending ``_r`` to the name. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # A colormap can be reversed by appending ``_r`` to the name. For example: | |
| # The built in colormaps have a reversed version named with a ``_r`` | |
| # appended to the name. For example: |
Adding the _r does not reverse the color map, we generate the reverse color maps by calling cm.reversed() in
matplotlib/lib/matplotlib/cm.py
Lines 40 to 57 in 5c45952
| def _gen_cmap_registry(): | |
| """ | |
| Generate a dict mapping standard colormap names to standard colormaps, as | |
| well as the reversed colormaps. | |
| """ | |
| cmap_d = {**cmaps_listed} | |
| for name, spec in datad.items(): | |
| cmap_d[name] = ( # Precache the cmaps at a fixed lutsize.. | |
| colors.LinearSegmentedColormap(name, spec, _LUTSIZE) | |
| if 'red' in spec else | |
| colors.ListedColormap(spec['listed'], name) | |
| if 'listed' in spec else | |
| colors.LinearSegmentedColormap.from_list(name, spec, _LUTSIZE)) | |
| # Generate reversed cmaps. | |
| for cmap in list(cmap_d.values()): | |
| rmap = cmap.reversed() | |
| cmap_d[rmap.name] = rmap | |
| return cmap_d |
It may be worth documenting the reversed method as well.

PR Summary
changed the note about reversing a colormap into a section of the colormap reference 'cause it was kind of buried in the preamble
PR Checklist
Tests and Styling
pytestpasses).flake8-docstringsand runflake8 --docstring-convention=all).Documentation
doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).