擅长:python、mysql、java
<p>我自己想出来的。我可以首先创造出正确的形状。在</p>
<pre><code>import pylab as plt
import numpy as np
import colorsys
W = 512
H = 256
hsls = np.ndarray(shape=(W, H, 3), dtype=float)
hsls[:] = .0
baseCol = np.linspace(0, 1, H)[np.newaxis, :]
print baseCol.shape, hsls.shape # Gives: (256, 1) (256, 512, 3)
hsls[:, :, 0] = np.tile(baseCol, (W, 1))
hsls[:, :, 1:3] = 0.5 # Use constant saturation and lightness.
vfunc = np.vectorize(colorsys.hsv_to_rgb)
rgbs = np.flipud(np.array(vfunc(hsls[:, :, 0], hsls[:, :, 1], hsls[:, :, 2])).transpose())
im = plt.imshow(rgbs, interpolation='nearest', aspect='auto')
plt.colorbar(im, orientation='horizontal')
plt.show()
</code></pre>
<p>结果是:
<img src="https://i.stack.imgur.com/BbcNI.png" alt="enter image description here"/></p>