<p>让我们从浏览现有代码开始</p>
<pre><code># get some uniformly sampled data, padded out a bit
colors_i = np.concatenate((np.linspace(0, 1., N), (0.,0.,0.,0.)))
# sample the input colormap at our sample points
colors_rgba = cmap(colors_i)
# indices for color map
indices = np.linspace(0, 1., N+1)
# dict to pass to the LinearSegmentedColormap
cdict = {}
# loop over the colors
for ki,key in enumerate(('red','green','blue')):
# in each color assemble a list that looks like
#[...,
# (indices[2], colors_rgba[1,ki], colors_rgba[2,ki]),
# (indices[3], colors_rgba[2,ki], colors_rgba[3,ki]),
# ....]
cdict[key] = [ (indices[i], colors_rgba[i-1,ki], colors_rgba[i,ki]) for i in xrange(N+1) ]
# The color for a number between [indices[2], indices[3]] are interpolated
# between colors_rgba[2,ki] and colors_rgba[2,ki] which are the same
# which is what gives you the discrete blocks.
# Construct and return colormap object.
return cols.LinearSegmentedColormap(cmap.name + "_%d"%N, cdict, 1024)
</code></pre>
现在的问题是如何在中间创建一个“双”白色带的彩色地图。我会改变功能位,让它接受两个彩色地图(顶部和底部)</p>
^{pr2}$
<p><img src="https://i.stack.imgur.com/vPRsa.png" alt="enter image description here"/></p>
<p>您可以轻松地修改此选项,以便在两个以上的颜色贴图之间分割。在</p>