擅长:python、mysql、java
<p>LinearSegmentedColormap不会提供相同的插值,如果我在测试期间不手动进行插值,那么我更喜欢使用我自己的:</p>
<p>作为一个优点,matplotlib并不需要,因为我将代码集成到现有软件中。在</p>
<pre><code>def codeBook(color_list, N=256):
"""
return N colors interpolated from rgb color list
!!! workaround to matplotlib colormap to avoid dependency !!!
"""
# seperate r g b channel
rgb = np.array(color_list).T
# normalize data points sets
new_x = np.linspace(0., 1., N)
x = np.linspace(0., 1., len(color_list))
# interpolate each color channel
rgb = [np.interp(new_x, x, channel) for channel in rgb]
# round elements of the array to the nearest integer.
return np.rint(np.column_stack( rgb )).astype('int')
</code></pre>