164种默认colormap样式【附图】

找到了这篇,还有分类Python 画图常用颜色
82种基本样式,每一种添加_r后可反转颜色,例如AccentAccent_r

常用备忘
Accent,Blues,BrBG,BuGn,BuPu,bwr,cividis,coolwarm,GnBu,Pastel1,Pastel2,RdBu,RdGy,RdYlBu,Set2,Set3,Spectral,tab20,twilight_shifted

获取方法
plt.colormaps()plt.cm._gen_cmap_d()

实现代码

def get_data(n):
    x = np.linspace(0, 10, n)
    y = np.zeros([n, n])
    for i in range(n):
        y[i, :] = list(map(lambda x:i, x))
    return x, y
    
t_count = 0
cm_ls = sorted(plt.colormaps(), key=str.lower)
cm_ls = [i for i in cm_ls if '_r' not in i]
page = 0
shape = (6, 4, 24)  # 横,纵,乘积
p = 80  # 间距
x, y = get_data(p)

while page * shape[2] < len(cm_ls):
    plt.figure(figsize=(15, 20))
    for i in range(1, shape[2] + 1):  
        if t_count >= len(cm_ls):
            break
        ax = plt.subplot(*shape[:2], i)

        cm_name = cm_ls[t_count]
        cm = plt.cm._gen_cmap_d()[cm_name]        
        cm = cm(np.linspace(0, 1, p))

        for n, i in enumerate(y):
            ax.plot(x, i, c=cm[n], lw=5)
        ax.set_xlabel(cm_name, fontsize=28)
        ax.set_xticks([])
        ax.set_yticks([])
        t_count += 1
    plt.savefig(r'C:\Users\Administrator\Desktop\%d.png' % (page+1), bbox_inches='tight', dpi=100)
    page += 1

164种默认colormap样式【附图】_第1张图片
164种默认colormap样式【附图】_第2张图片
164种默认colormap样式【附图】_第3张图片
164种默认colormap样式【附图】_第4张图片

你可能感兴趣的:(matplotlib)