/usr/lib/python3/dist-packages/photutils/utils/colormaps.py is in python3-photutils 0.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import numpy as np
from .check_random_state import check_random_state
__all__ = ['random_cmap']
def random_cmap(ncolors=256, random_state=None):
"""
Generate a matplotlib colormap consisting of random (muted) colors.
A random colormap is very useful for plotting segmentation images.
Parameters
----------
ncolors : int, optional
The number of colors in the colormap. The default is 256.
random_state : int or `~numpy.random.RandomState`, optional
The pseudo-random number generator state used for random
sampling. Separate function calls with the same
``random_state`` will generate the same colormap.
Returns
-------
cmap : `matplotlib.colors.Colormap`
The matplotlib colormap with random colors.
"""
from matplotlib import colors
prng = check_random_state(random_state)
h = prng.uniform(low=0.0, high=1.0, size=ncolors)
s = prng.uniform(low=0.2, high=0.7, size=ncolors)
v = prng.uniform(low=0.5, high=1.0, size=ncolors)
hsv = np.dstack((h, s, v))
rgb = np.squeeze(colors.hsv_to_rgb(hsv))
return colors.ListedColormap(rgb)
|