map_colors#
- k3d.helpers.map_colors(attribute, color_map, color_range=())[source]#
Return color mapping according to an attribute and a colormap.
The attribute represents the data on which the colormap will be apply. The color range allows to constraint the colormap between two values.
- Parameters
attribute (ndarray) – Array of numbers.
color_map (array_like) – Array of numbers.
color_range (tuple, optional) – Two numbers, by default ().
- Returns
Color mapping.
- Return type
ndarray
Examples#
Color range#
import k3d
import numpy as np
attribute = np.linspace(0, 1, 100)
color_map = k3d.basic_color_maps.Jet
colors = k3d.helpers.map_colors(attribute, color_map, color_range=[0.5, 0.6])
"""
array([ 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 163, 214,
2815, 15615, 28671, 41727, 54527, 589814,
3932099, 7274384, 10551134, 13893419, 16774912, 16762112,
16749056, 16736000, 16722944, 16318464, 12976128, 9633792,
8323072, 8323072, 8323072, 8323072, 8323072, 8323072,
8323072, 8323072, 8323072, 8323072, 8323072, 8323072,
8323072, 8323072, 8323072, 8323072, 8323072, 8323072,
8323072, 8323072, 8323072, 8323072, 8323072, 8323072,
8323072, 8323072, 8323072, 8323072, 8323072, 8323072,
8323072, 8323072, 8323072, 8323072, 8323072, 8323072,
8323072, 8323072, 8323072, 8323072], dtype=int32)
"""
No color range#
import k3d
import numpy as np
attribute = np.linspace(0, 1, 100)
color_map = k3d.basic_color_maps.Jet
colors = k3d.helpers.map_colors(attribute, color_map)
"""
array([ 8912759, 9240434, 9568109, 9895784, 10223459, 10551134,
10878809, 11206484, 11599694, 11927369, 12255044, 12582719,
12910394, 13238069, 13565744, 13893419, 14221094, 14548769,
14876444, 15204119, 15531794, 15859469, 16252679, 16580354,
16776192, 16774912, 16773632, 16772352, 16771072, 16769792,
16768512, 16767232, 16765952, 16764672, 16763392, 16762112,
16760576, 16759296, 16758016, 16756736, 16755456, 16754176,
16752896, 16751616, 16750336, 16749056, 16747776, 16746496,
16745216, 16743936, 16742400, 16741120, 16739840, 16738560,
16737280, 16736000, 16734720, 16733440, 16732160, 16730880,
16729600, 16728320, 16727040, 16725760, 16724224, 16722944,
16721664, 16720384, 16719104, 16717824, 16716544, 16715264,
16713984, 16712704, 16646144, 16318464, 15990784, 15663104,
15269888, 14942208, 14614528, 14286848, 13959168, 13631488,
13303808, 12976128, 12648448, 12320768, 11993088, 11665408,
11337728, 11010048, 10616832, 10289152, 9961472, 9633792,
9306112, 8978432, 8650752, 8323072], dtype=int32)
"""