Skip to content

ENH: add a copy method to colormaps #19663

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

Merged
merged 2 commits into from
Mar 9, 2021

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 7, 2021

PR Summary

Right now we are deprecating access to the global colormaps, but users can only avoid it by doing newcmap = copy.copy(cmap) which is a bit heavy-handed. Here we provide a simple copy method to Colormap so we can do newcmap = cmap.copy().

See discussion in #19609, #16991, #18503

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

While I don't want to put a copy() method on every object, it makes sense here. With this method we make copying simpler and thus promote the needed copying at least for the transition period.

Milestoned for 3.4 - this should have been already introduced with the changes in 3.3. If we don't get it in 3.4 a major purpose ( the easier user-copy workaround in the transition period) is gone.

@timhoffm timhoffm added this to the v3.4.0 milestone Mar 7, 2021
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@jklymak
Copy link
Member Author

jklymak commented Mar 7, 2021

Agreed, that we definitely don't want a copy method on everything. But most classes aren't primarily coming from global instances, and hence usually can be made from scratch. Whereas colormaps are probably 99% coming from the global list, so I think we should make it easy to move into user scope.

@QuLogic QuLogic merged commit fba5d15 into matplotlib:master Mar 9, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 9, 2021
@jklymak jklymak deleted the enh-add-colormap-copy branch March 9, 2021 02:15
QuLogic added a commit that referenced this pull request Mar 9, 2021
…663-on-v3.4.x

Backport PR #19663 on branch v3.4.x (ENH: add a copy method to colormaps)
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.

3 participants