Thanks to visit codestin.com
Credit goes to github.com

Skip to content

added option to get_cmap("random") in cm.ColormapRegistry #24340

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

Closed
wants to merge 564 commits into from
Closed

added option to get_cmap("random") in cm.ColormapRegistry #24340

wants to merge 564 commits into from

Conversation

augustvanhout
Copy link

PR Summary

Added option to pass the string "random" to get_cmap function within cm.ColormapRegistry class.
Two lines of code, just looks up a np.random.choice(_colormap) from mpl.colormaps and returns it

First pull request, any advice welcome. Added some comments, change is tiny.
Thanks very much.

PR Checklist

Tests and Styling

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

Documentation

  • [N/A ] 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

QuLogic and others added 30 commits October 8, 2022 01:02
…thod

FIX: add missing method to ColormapRegistry
Bump version when invalid hatches error
DOC: align contour parameter doc with implementation
Due to inconsistencies in the colormap setup, it is suggested to instead
check for `get_array` to get an array of values to be color mapped. This
check is more robust irrespective of whatever the type of colormap is
set to be.
Tests are added to check various conditions for the text color for a
legend set with `linecolor`, `markeredgecolor`, `markerfacecolor` in a
scatter plot.
)

* ENH: Add pan and zoom toolbar handling to 3D Axes

1) This moves the pan logic that was already in the mouse move handler
into the "drag_pan" method to make it available from the toolbar.

2) This expands upon the panning logic to enable a zoom-to-box feature.
The zoom-to-box is done relative to the Axes, so it shrinks/expands
the box as a fraction of each delta, from lower-left Axes to lower-left
zoom-box. Thus, it tries to handle non-centered zooms, which adds more
cases to handle versus the current right-click zoom only scaling from
the center of the projection.

* Rewrite zooming with bounding box

* Rewrite 3d panning to work with a roll angle

* Whats new for zoom and pan buttons

* Make pan button configurable

* Do not jump when zooming and mouse goes over other subplot

* Rework zooming for 3d plots

* Handle x/y lock when zooming and panning

* Update tests

* Docstrings

* Dont assume a scale_z

* Limit zoom box

* Test zoom pan key modifiers

* Save some calculation by saving view axes

* Deprecation warnings for Axes3D.eye, .vvec

* Remove Axes3D._prepare_view_from_bbox for now

* Comments and docstrings

* Switch from uvn to uvw

* Save aspect to axes

* Constrain zooming with mouse when one of the equal aspect ratios is set

* Cleanup

* Cleanup

* Consolidate finding equal aspect axis indices

* linting

* More intuitive scaling

* Box zoom keeps existing aspect ratios

* Linting

* Code review comments

* Revert parameters for view_transformation

* Fix new 3d pan/zoom view going on view stack twice

* Better clipping

* Test 3d toolbar navigation

* Privatize helper functions

* Deprecations

* Code review changes

* Deprecation note

* Undeprecate proj3d.view_transformation

* Undeprecate proj3d.view_transformation

* Update doc/api/next_api_changes/deprecations/23449-SS.rst


Co-authored-by: Greg Lucas <[email protected]>
Co-authored-by: Scott Shambaugh <[email protected]>
Co-authored-by: Oscar Gustafsson <[email protected]>
Inherit OffsetBox.get_window_extent.
Add QuadContourSet.remove.
ContourLabeler previously optionally used a custom Text subclass to
ensure that text rotation took place in data space, not in screen space,
but this is now available for all Text instances via the
transform_rotates_text property, so directly use that.  This means that
_get_label_text, _add_label, and set_label_props can also directly get
inlined into their now only callsite (add_label).
Replace ClabelText by set_transform_rotates_text.
The deprecated attributes cannot be updated after the ContourLabeler has
been set up (i.e. if the end user overwrites them it does not update the
labels) *and* all have direct replacements available.  We could consider
later adding new getters/setters (`get/set_font_properties`) which would
actually update the properties on the label texts.

While at it, prefer using `manual` over the equivalent but longer
`self.labelManual`; `_get_nth_label_width` doesn't need to explicitly
set the text size as that info is also carried by the fontproperties
object.
* Add note about blitting and zorder in animations

Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Elliott Sales de Andrade <[email protected]>
Co-authored-by: hannah <[email protected]>
MNT: Clean up code in SecondaryAxis
Simplest pyproject.toml containing build-system only
ksunden and others added 15 commits October 31, 2022 19:22
…ypa/cibuildwheel-2.11.2

Bump pypa/cibuildwheel from 2.11.1 to 2.11.2
Small cleanups to QuiverKey.
show axes changing in animate decay example
Simplify generate_fontconfig_pattern.
Unify logic of ConnectionStyle._Base.{_clip,_shrink}.
GOV: change security reporting to use tidelift
Compare with the docstring of ImageMagickFileWriter just below.
Fix missing word in ImageMagickWriter docstring.
Update example and docstring to encourage the use of functools.partial in FuncAnimation
Add shading of Poly3DCollection
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@ksunden
Copy link
Member

ksunden commented Nov 2, 2022

Thank you for your interest in contributing to Matplotlib!

Firstly, all PRs should be made to the main branch (i.e. not the v3.6.x branch as this was opened against).

For more complete description see our PR Guidelines

I'm struggling to think of a use-case where it makes sense to blindly grab a random colormap. Color map choice is deeply tied to the kind of data you are visualizing: e.g. do you want a sequential colormap versus diverging or categorical?
My first instinct is to say that this is something that is easy enough for the edge case of somebody who is interested in a random colormap to implement themselves.
(Also, it would prevent adding a colormap that is called "random" which would have been perfectly fine prior)

Could you clarify why you feel this is needed?

@timhoffm
Copy link
Member

timhoffm commented Nov 2, 2022

Thanks for the initiative to contribute! However, I decline this feature. It's very rare that people want a random colormap. Usually you want to control your output. Moreover, different kinds of colormaps (linear, biopolar, ...) are suited for different kinds of data, so I strongly advise against using a random colormap.

That said, if you really want a random colormap you can easily get one using builtin functionality:

import random
import matplotlib.pyplot as plt

random.choice(list(plt.colormaps.values()))

or use keys() instead of values() if you want a name.

@timhoffm timhoffm closed this Nov 2, 2022
@augustvanhout
Copy link
Author

augustvanhout commented Nov 2, 2022 via email

@story645
Copy link
Member

story645 commented Nov 2, 2022

try googling https://www.google.com/search?q=get+random+colormap+from+matplotlib for that solution you made.

It looks like many of those folks are trying to solve a different problem, which is distinct colors for categories, and distinctpy is a good solution that we could probably advertise more.

I've watched people - instructors, even - spend minutes looking through your options and* trying a bunch until they get one their gut likes.*

I agree that's a real problem, would something like a plt.colormaps.display() method that displays all the colormaps work better? That's currently achievable in notebooks as

from IPython.display import display
for cm in plt.colormaps.keys():
    display(plt.colormaps[cm])

and prints all the colormaps, but would something more condensed be a better way of approaching this problem?

@augustvanhout
Copy link
Author

augustvanhout commented Nov 2, 2022 via email

@story645
Copy link
Member

story645 commented Nov 2, 2022

Besides, if people keep scrolling through cmaps, might as well make it as easy as passing “random”.

But guaranteeing no duplicates in the random in each session is probably a lot of code overhead, so aren't you betting on them finding one they like fairly quickly? And if they don't, my guess is it ends up as a more exhaustive search than printing the maps w/o the benefit of seeing the other options?

To be clear, while I think random is really fun and I kinda want it as a bot, I agree with Kyle and Tim that I'm having trouble seeing it as in scope for the library for the reasons they mentioned.

@augustvanhout
Copy link
Author

augustvanhout commented Nov 3, 2022 via email

@story645
Copy link
Member

story645 commented Nov 3, 2022

I edited your comment so it links to the github upload of your video 'cause I figure folks (like me) would be a little freaked at clicking a random download link

@augustvanhout
Copy link
Author

augustvanhout commented Nov 3, 2022 via email

@story645
Copy link
Member

story645 commented Nov 3, 2022

So I really want your video for the matplotlib instagram/tiktok/twitter, where I can share it w/ the code.

Your video also sold me on a new example in the colors section of the gallery showing this since that section is kind of sparse and we can title it getting a random colormap 'cause we don't really have a demo of just the registry and that section is all reference. <- this though would need support of a second dev since we have 660+ examples.

@augustvanhout
Copy link
Author

augustvanhout commented Nov 3, 2022 via email

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.