是否有与 tab20c 类似的调色板,颜色数量更多? [英] Is there a similar color palette to tab20c with bigger number of colors?

查看:28
本文介绍了是否有与 tab20c 类似的调色板,颜色数量更多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有关颜色图的

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

解决方案

如果你能在

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

N = 10 # 从下面的每个 base_cmap 中提取的颜色数base_cmaps = ['灰色','紫色','红色','蓝色','橙色','绿色']n_base = len(base_cmaps)#我们从0.2降低到0.8以下,以避免在生成的cmap中出现多个白色和黑色colors = np.concatenate([base_cmaps中的名称为[plt.get_cmap(name)(np.linspace(0.2,0.8,N))]])cmap = matplotlib.colors.ListedColormap(colors)梯度= np.linspace(0,1,256)梯度 = np.vstack((梯度,梯度))无花果,ax = plt.subplots(1,1,figsize =(5,1))ax.imshow(渐变,aspect='auto',cmap=cmap)

Here's the reference about the colormaps.

Here's the tab20c colormap:

I want a similar colormap (such that every color is really different from each other) but it should contain more than 20 colors. Is there any other options?

解决方案

If you can find a divergent colormap that you like in the page you linked, you can easily generate your own segmented colormap using 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()

You could also create your own cmap by assembling different cmaps like so:

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)

这篇关于是否有与 tab20c 类似的调色板,颜色数量更多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆