Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

story645
Copy link
Member

@story645 story645 commented Sep 15, 2022

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

image

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

A reversed version of each of these colormaps is available by appending
``_r`` to the name, e.g., ``viridis_r``.
Copy link
Member

@jklymak jklymak Sep 16, 2022

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

# A reversed version of any colormap is available by appending ``_r`` to the
# name, for example:

plot_color_gradients("Reversed ",
Copy link
Member

@timhoffm timhoffm Sep 16, 2022

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?

Copy link
Member Author

@story645 story645 Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was going back and forth on that (they're just the first map of each section) as this is the tweet that inspired this PR
image

I think it felt too small, but also yes if it ain't broke...

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:
Copy link
Member

@tacaswell tacaswell Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants