From b636eea0131a0a246cf34226b524da5d583f68f0 Mon Sep 17 00:00:00 2001 From: augustvanhout <84168376+augustvanhout@users.noreply.github.com> Date: Mon, 7 Nov 2022 19:01:21 -0500 Subject: [PATCH] added random colormap option to cm.py, venv tested, docstrings stylized, etc --- lib/matplotlib/cm.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index cd5e952649ea..030da05f44b1 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -704,6 +704,14 @@ def changed(self): ) +def get_random_cmap(): + """ + Returns a colormap at random from _colormaps + + """ + return _get_cmap(np.random.choice(_colormaps)) + + def _ensure_cmap(cmap): """ Ensure that we have a `.Colormap` object. @@ -715,6 +723,7 @@ def _ensure_cmap(cmap): cmap : None, str, Colormap - if a `Colormap`, return it + - if "random", return a random Colormap with get_random_cmap() - if a string, look it up in mpl.colormaps - if None, look up the default color map in mpl.colormaps @@ -725,6 +734,8 @@ def _ensure_cmap(cmap): """ if isinstance(cmap, colors.Colormap): return cmap + if cmap == "random": + return get_random_cmap() cmap_name = cmap if cmap is not None else mpl.rcParams["image.cmap"] # use check_in_list to ensure type stability of the exception raised by # the internal usage of this (ValueError vs KeyError)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: