示例图片


前言

众所周知,MATLAB中的colormap只有少得可怜的几种:

有很多应用在很特殊的图形中的colormap几乎都没有,而每次写代码都要去找颜色图属实太麻烦,因此就有了开发集成包的想法,我之前出过一篇使用python全部配色的文章,但是代码写的比较飘导致老版本用不了,这次使用了比较基础的代码和调用方式,争取能让更多人能用上。

matplotlab颜色新增了一些,但这哪够,于是我将:

  • matplotlab
  • scicomap
  • cmasher
  • viscm

包全部集成了进来,终于有了这套包含200个colormap的工具函数slanCM


颜色展示

Perceptually Uniform Sequential 感知一致 colormap:

Pure Sequential 颜色较纯单方向渐变:

较复杂渐变:

Diverging 双方向渐变:

Cyclic 循环渐变(两侧颜色可以对接在一起):

Miscellaneous 混杂渐变色,用于一些山地、光谱等特殊图绘制:

Qualitative 离散colormap:


使用方法

不指定获取颜色个数会默认256色,举例获取[163]号彩虹色(rainbow),以下两种写法等价:

  • slanCM(‘rainbow’)
  • slanCM(163)

第二个参数可以指定获取颜色数量,例如获取30颜色:

  • slanCM(‘rainbow’,30)
  • slanCM(163,30)

将获取的颜色放入colormap函或者某些图像的CData即可,例如:

  • colormap(slanCM(‘rainbow’))

实际例子

demo1 曲面图

使用上述

  • colormap(slanCM(‘rainbow’))

进行颜色修改:

% demo1
surf(peaks,'EdgeColor','w','EdgeAlpha',.3)
% 使用slanCM的彩虹配色
colormap(slanCM('rainbow'))% 修饰一下
ax=gca;
ax.Projection='perspective';
ax.LineWidth=1.2;
ax.XMinorTick='on';
ax.YMinorTick='on';
ax.ZMinorTick='on';
ax.GridLineStyle=':';
view(-37,42)

demo2 imagesc

使用100号配色:

% demo2
XData=rand(15,15);
XData=XData+XData.';
H=fspecial('average',3);
XData=imfilter(XData,H,'replicate');imagesc(XData)
% 使用slanCM的100号配色
colormap(slanCM(100))
hold onax=gca;
ax.DataAspectRatio=[1,1,1];
ax.LineWidth=1.2;
ax.XMinorTick='on';
ax.YMinorTick='on';
ax.ZMinorTick='on';
ax.GridLineStyle=':';
view(-37,42)

demo3 灰度图

使用离散颜色:

% demo3
rgbImage=imread("peppers.png");
imagesc(rgb2gray(rgbImage))colormap(slanCM('prism2'))

demo4 特殊地形配色

使用特殊地形配色terrain

% demo4
X=linspace(0,1,200)';
CL=(-cos(X*2*pi)+1).^.2;
r=(X-.5)'.^2+(X-.5).^2;
surf(X,X',abs(ifftn(exp(7i*rand(200))./r.^.9)).*(CL*CL')*30,'EdgeColor','none')colormap(slanCM('terrain'))
light
material dull
view(59.1823,56.1559)% 修饰一下
ax=gca;
ax.Projection='perspective';
ax.LineWidth=.8;
ax.XMinorTick='on';
ax.YMinorTick='on';
ax.ZMinorTick='on';
ax.GridLineStyle=':';

加个光照:

demo5 多colormap

% demo5
X=linspace(0,1,200)';
CL=(-cos(X*2*pi)+1).^.2;
r=(X-.5)'.^2+(X-.5).^2;
Z=abs(ifftn(exp(7i*rand(200))./r.^.9)).*(CL*CL')*30;ax1=axes('Parent',gcf,'OuterPosition',[0,1/2,1/2,1/2],'LooseInset',[0,0,0,0]);
contourf(Z,'EdgeColor','none')
ax1.Colormap=slanCM('tokyo',200);ax2=axes('Parent',gcf,'OuterPosition',[1/2,1/2,1/2,1/2],'LooseInset',[0,0,0,0]);
contourf(Z,'EdgeColor','none')
ax2.Colormap=slanCM('sepia',200);ax3=axes('Parent',gcf,'OuterPosition',[0,0,1/2,1/2],'LooseInset',[0,0,0,0]);
contourf(Z,'EdgeColor','none')
ax3.Colormap=slanCM('turku',200);ax4=axes('Parent',gcf,'OuterPosition',[1/2,0,1/2,1/2],'LooseInset',[0,0,0,0]);
contourf(Z,'EdgeColor','none')
ax4.Colormap=slanCM('copper2',200);

demo6 帅气的分形

% demo6
% MvLevi :https://ww2.mathworks.cn/matlabcentral/communitycontests/contests/5/entries/10775
C=-9:9e-3:9;D=-9:9e-3:9;
for q=1:2001for j=1:2001X=.5;for i=1:5if mod(i,2)==0X(i+1)=X(i)-C(q)*(.5+.3*cos(X(i)))^-1;elseX(i+1)=X(i)-D(j)*(.5+.3*cos(X(i)))^-1;endendP=diff(X);L(q,j)=mean(log(abs(P)));end
end
pcolor(C,D,-L)
shading flat
axis off
caxis([-3.5 3.5])colormap(slanCM('twilight'))

demo7 渐变柱状图

多试了几个颜色:

% demo7
X=randi([2,15],[1,25])+rand([1,25]);
b=bar(X);CMap=slanCM('hsv');
b.FaceColor='flat';
b.CData=slanCM(188,length(b.XData));
% 42 56 63 100 133 187 188% 修饰一下
ax=gca;hold on;grid on
ax.DataAspectRatio=[1,1,1];
ax.LineWidth=1.2;
ax.XMinorTick='on';
ax.YMinorTick='on';
ax.ZMinorTick='on';
ax.GridLineStyle=':';

demo8 散点图

% demo8
rng('default')
for i = 1:20000x = -0.4 + 0.8*randi([0 1],1,18);A = gallery('circul',x);E(:,i) = eig(A);
end
scatter(real(E(:)),imag(E(:)),8,'filled','CData',slanCM('twilight',length(E(:))))
xlabel('Re(E)')
ylabel('Im(E)')
xlim([-3 3])
ylim([-3 3])
axis square

demo9 气泡图

% demo9
x=1:30;
[~,ind]=sort(rand(1,30));
x=x(ind);
y=rand(1,30);
sz=sort(rand(1,30));% 100 102 94
bubblechart(x,y,sz,'CData',slanCM(94,30));% 修饰一些
ax=gca;hold on
ax.LineWidth=.8;


另(建议略过)

鉴于一部分人问过我咋从python获取颜色,这里给两段python代码:

matplotlab获取全部颜色:

import numpy as np
import matplotlib.pyplot as pltcmaps = [('Perceptually Uniform Sequential', ['viridis', 'plasma', 'inferno', 'magma', 'cividis']),('Sequential', ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),('Sequential (2)', ['binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink', 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper']),('Diverging', ['PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),('Cyclic', ['twilight', 'twilight_shifted', 'hsv']),('Qualitative', ['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b', 'tab20c']),('Miscellaneous', ['flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet', 'turbo', 'nipy_spectral', 'gist_ncar'])]
def plot_color_gradients(cmap_category, cmap_list):print(cmap_category)print(cmap_list)for color in cmap_list:np.savetxt(color+'.txt', np.c_[plt.get_cmap(color)(np.linspace(0, 1, 256))],fmt='%f',delimiter='\t')
for cmap_category, cmap_list in cmaps:plot_color_gradients(cmap_category, cmap_list)

scicomap获取全部颜色:

import numpy as np
import matplotlib.pyplot as plt
import scicomap as sc
import numpy as npsc_map = sc.SciCoMap()
typeList=sc_map.get_ctype()
print(typeList)
sc_dic=sc.get_cmap_dict()for i in typeList:tdic=sc_dic[i]print('-----------------')for j in tdic.keys():color=tdic[j]np.savetxt(j+'.txt', np.c_[plt.get_cmap(color)(np.linspace(0, 1, 256))],fmt='%f',delimiter='\t')print(j)

两百组数据整理起来真真真真的巨累,希望大家该点赞的点赞,该在看的在看!!

未经允许本代码请勿作商业用途,引用的话可以引用我file exchange上的链接,可使用如下格式:

Zhaoxu Liu (2022). 200 colormap (https://www.mathworks.com/matlabcentral/fileexchange/120088-200-colormap), MATLAB Central File Exchange. 检索来源 2022/11/6.

若转载请保留以上file exchange链接及本文链接!!!!!

完整工具函数及示例:
更新时会跟进更新以下连接:
【链接】:https://pan.baidu.com/s/13-EfxRoP4A7HS_gunShNPg?pwd=slan
【提取码】:slan

MATLAB | MATLAB配色不够用 全网最全的colormap补充包来啦相关推荐

  1. 肝了三天,整了一份全网最全(中文) tcpdump 抓包指南

    今天要给大家介绍的一个 Unix 下的一个 网络数据采集分析工具,也就是我们常说的抓包工具. 与它功能类似的工具有 wireshark ,不同的是,wireshark 有图形化界面,而 tcpdump ...

  2. 重磅!整整159份!全网最全数字化转型资料包

    群里经常有要资料的,我基本上是有求必应.但是群里的消息毕竟零散,所以特意整一个帖子,把我手头上的资料做一个合集,提供给大家,作为51假期的小礼物,请您笑纳. 资料分十二部分,一共159份!文末有下载方 ...

  3. 全网最全Linux 运行jar包的几种方式

    一.Linux 运行jar包的几种方式 方式一: java -jar xxx.jar 最常用的启动jar包命令,特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出 ...

  4. MATLAB | MATLAB海洋、气象数据colormap配色补充包(NCL color tables)

    众所周知,海洋.气象.水文等一系列学科绘制图像时,因很多时候涉及要将陆地海洋分开或者应对一些非常特殊的情况,因此有很多非常特别的colormap,我之前虽然做过一些常用colormap的补充包但是依旧 ...

  5. 粉丝福利!Matlab自动配色神器ColorForFans

    这几天回顾了一下之前制作的几个配色补充包,像配色强化addcolorplus: 450种常用颜色colorplus: 中国传统颜色color320: 以及英国传统颜色color328: 当初制作这些配 ...

  6. Matlab 增加配色方案

    (1) Matlab 提取已有的论文配色 参考此链接(https://www.its304.com/article/SDAU_LY124/105635548) 可以将论文里或者其他网站和软件上好看的颜 ...

  7. mapper命名规范_Mybatis系列全解(五):全网最全!详解Mybatis的Mapper映射文件

    封面:洛小汐 作者:潘潘 若不是生活所迫,谁愿意背负一身才华. 前言 上节我们介绍了 < Mybatis系列全解(四):全网最全!Mybatis配置文件 XML 全貌详解 >,内容很详细( ...

  8. 别再找了!全网最全的数据分析全流程攻略在这

    试想这样一个场景: 领导说:"你去建材市场帮我买些配件."你顶着烈日跑遍大小市场,但领导问你:"为何选这家?"你却答不上来. 你没努力吗?努力了.但有成效吗?至 ...

  9. Mybatis系列全解(五):全网最全!详解Mybatis的Mapper映射文件

    封面:洛小汐 作者:潘潘 若不是生活所迫,谁愿意背负一身才华. 前言 上节我们介绍了 < Mybatis系列全解(四):全网最全!Mybatis配置文件 XML 全貌详解 >,内容很详细( ...

  10. 全网最全安全加固指南

    干货 | 全网最全安全加固指南 安全加固相关概念阐述 安全加固定义 安全加固和优化是实现信息系统安全的关键环节.通过安全加固,将在信息系统的网络层.主机层.软件层.应用层等层次建立符合安全需求的安全状 ...

最新文章

  1. shell判断文件是否存在[转]
  2. 手工机器人的做法大全用易拉罐_纯手工自制黄油,做法简单详细易操作,蛋糕、饼干、面包都能用...
  3. 不能头脑一热,就布局颠覆性技术、上马未来产业
  4. C++设计模式-代理模式
  5. Serverless实战 —— 函数计算如何访问 MySQL 数据库
  6. atitit.提升性能AppCache
  7. mysql 升序和降序
  8. 节奏大师-触动脚本(源码)
  9. 定理证明器HOL的下载和安装
  10. qq系统软件测试计划,软件测试设计报告案例——qq空间.doc
  11. 李佳明的成长经历与留学选择
  12. Windows系统中电脑无法进入睡眠状态的解决办法
  13. 第2节--深度学习基础介绍-机器学习--课程介绍(下)
  14. PSpice中VPulse的设置问题
  15. 什么是HSS?HSS有什么主要功能?HSS与HLR的区别是什么?
  16. gin学习——邮箱发送验证码注册用户
  17. 线性递推数列_学习笔记
  18. 【JZOJ5353】【NOIP2017提高A组模拟9.9】村通网【最小生成树】
  19. virtual box安装Linux系统并关闭防火墙
  20. 测量平差之附有限制条件的间接平差

热门文章

  1. 李彦宏遭遇“泼水门”,气质淡定冲上热搜
  2. JS内功修炼-基础篇
  3. 怎么把PPT幻灯片里背景图片拿出来
  4. “伊”心一意研技术,“伊”丝不苟做服务。Electropure EDI 成功参展第12届上海国际水展
  5. 超过2t硬盘分区_大于2T的硬盘怎么分区
  6. IPFS独角兽西部世界解读:销毁的近2000万FIL去哪里了?
  7. c++随手写写(链表栈)
  8. 小生意同样能赚大钱,卖豆芽都能一年存20多万?你怎么看?
  9. 一起学爬虫(Python) — 09
  10. win7浏览器主页修改不过来_win7浏览器主页不能修改怎么办 win7浏览器主页不能修改解决方法...