是否有与 tab20c 类似且颜色数量更多的调色板?

2023-12-10

这是参考关于颜色图。

Here's the tab20c colormap: enter image description here

我想要一个类似的颜色图(这样每种颜色都彼此不同),但它应该包含 20 多种颜色。还有其他选择吗?


如果您能找到您喜欢的不同颜色图您链接的页面,您可以使用轻松生成自己的分段色彩图ListedColormap:

N = 30
test_cmaps = ['gist_rainbow','nipy_spectral','gist_ncar']
segmented_cmaps = [matplotlib.colors.ListedColormap(plt.get_cmap(t)(np.linspace(0,1,N))) for t in test_cmaps]


nrows = len(test_cmaps)
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))


def plot_color_gradients(cmap_category, cmap_list, nrows):
    fig, axes = plt.subplots(nrows=nrows)
    fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
    axes[0].set_title(cmap_category + ' colormaps', fontsize=14)

    for ax, name in zip(axes, cmap_list):
        ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
        pos = list(ax.get_position().bounds)
        x_text = pos[0] - 0.01
        y_text = pos[1] + pos[3]/2.
        fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

    # Turn off *all* ticks & spines, not just the ones with colormaps.
    for ax in axes:
        ax.set_axis_off()

plot_color_gradients('test', segmented_cmaps, nrows)
plt.show()

enter image description here

您还可以通过组装不同的 cmap 来创建自己的 cmap,如下所示:

N = 10 # number of colors to extract from each of the base_cmaps below
base_cmaps = ['Greys','Purples','Reds','Blues','Oranges','Greens']

n_base = len(base_cmaps)
# we go from 0.2 to 0.8 below to avoid having several whites and blacks in the resulting cmaps
colors = np.concatenate([plt.get_cmap(name)(np.linspace(0.2,0.8,N)) for name in base_cmaps])
cmap = matplotlib.colors.ListedColormap(colors)

gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))

fig, ax = plt.subplots(1,1,figsize=(5,1))
ax.imshow(gradient, aspect='auto', cmap=cmap)

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否有与 tab20c 类似且颜色数量更多的调色板? 的相关文章

随机推荐