1👍
You may use the following code:
from __future__ import division
import numpy
import matplotlib.cm as cmap
r = numpy.random.rand(1000) #random numbers
c = cmap.jet(numpy.int_((r-r.min())/r.ptp()*255)) #colors
so you try:
>>> r
array([ 0.88741281, 0.61022571, 0.14819983, 0.3695846 , 0.73832029,
0.6266069 , 0.6917337 , 0.09162752, 0.83532511, 0.54001574, ...,])
>>> c
array([[ 1. , 0.08787219, 0. , 1. ],
[ 0.83175206, 1. , 0.13598988, 1. ],
[ 0. , 0.08039216, 1. , 1. ],
...,
[ 0. , 0.72352941, 1. , 1. ],
[ 0.24984187, 1. , 0.71790006, 1. ],
[ 1. , 0.45098039, 0. , 1. ]])
which are colors each row in the format of RGBA.
0👍
you can also give a look at ColorConverter. It provides a few methods to convert valid matplotlib colors to RGB or RGBA.
Valid matplotlib colors are
- a letter from the set ‘rgbcmykw’
- a hex color string, like ‘#00FFFF’
- a standard name, like ‘aqua’ a float, like ‘0.4’, indicating gray on
- a 0-1 scale
Source:stackexchange.com