added random colormap option to cm.py (lines 705-740ish) by augustvanhout · Pull Request #24396 · matplotlib/matplotlib · GitHub
Skip to content

added random colormap option to cm.py (lines 705-740ish) - #24396

Closed
augustvanhout wants to merge 1 commit into
matplotlib:mainfrom
augustvanhout:random-colormap-option
Closed

added random colormap option to cm.py (lines 705-740ish)#24396
augustvanhout wants to merge 1 commit into
matplotlib:mainfrom
augustvanhout:random-colormap-option

Conversation

@augustvanhout

Copy link
Copy Markdown

PR Summary

Original PR #24340
Matplotlib has a huge number of colormaps and no way to quickly sample them! The above PR's comments contain spirited debate and a video of the proposed functionality - passing the argument 'cmap = "random"'

This PR adds a few lines to cm.py to allow coders everywhere to sample matplotlib's many colormaps on any plot they like, anytime they like.

Two things are changed in cm.py:
1) added one-liner function get_random_cmap() which returns a Colormap at random from _colormaps
2) added if statement to _ensure_cmap so that when a user passes "random" as a colormap, _ensure_cmap returns get_random_cmap()

And that's it.

The workflow was:
- Edit cmp.y and test functionality in venv
- Ensure flake8
- Run pytest - 1 depreciation warning when pickling
- Edit docstrings - went with precedent of other similarly short functions in cm.py
- Did not edit whats_new_next as feature is small

Attached is an example dataset (credit to Kaggle) as well as a script called random_colormap_test.py, which showcases the changes proposed.

melbourne.csv
random_colormap_test.txt

PR Checklist

Tests and Styling

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

Documentation

  • [NA] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/

  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/

  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@story645

story645 commented Nov 8, 2022

Copy link
Copy Markdown
Member

@jklymak

jklymak commented Nov 8, 2022

Copy link
Copy Markdown
Member

@augustvanhout thanks so much for your enthusiasm! However, maybe the level of consensus wasn't clear in #24340 because only two maintainers directly engaged. I am also strongly against this. I think if anyone disagreed with @timhoffm about closing the PR, we would have said. Hopefully we hear from you again, perhaps with a cool example as suggested by @story645

@augustvanhout

augustvanhout commented Nov 8, 2022 via email

Copy link
Copy Markdown
Author

@story645

story645 commented Nov 8, 2022

Copy link
Copy Markdown
Member

I’ll find some bugs to stomp… and maybe someday invent something more nuanced!

Turning this PR into a documentation PR is mostly the same code you used to make your video, but placed in https://github.com/matplotlib/matplotlib/tree/main/examples/color

@jklymak agreed that the example idea could work and for most docs you need one maintainer in agreement (here you've kinda got two) and nobody in opposition so far.

@tacaswell

Copy link
Copy Markdown
Member

@tacaswell tacaswell closed this Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants