added random colormap option to cm.py (lines 705-740ish) #24396
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
Release Notes
[N/A] New features are marked with a
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
[N/A] API changes are marked with a
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
[N/A] Release notes conform with instructions in
next_whats_new/README.rst
ornext_api_changes/README.rst