写了个函数,可以在MATLAB 中使用 python 全部 colormap 配色: (以下仅展示部分)
注意文件夹内一定要有:
- PYCM.m
- PYCMset.mat
两个文件 ,PYCM.m 为主函数,PYCMset.mat 为包含颜色数据及名称的 mat 文件,以下展示当前版本 PYCM.m 完整代码(完整m文件及颜色数据文件下载方式请查看文末):
function CM=PYCM
% @author: slandarer
% @公众号: slandarer随笔
% @知 乎: slandarer
% =====================================================
% 基本使用:
% PYCM().pink(n)
% PYCM().pink() % 未指定数目时默认返回100个RGB值
% PYCM().pink(50) % 获取名为pink的色带的50个数值
% PYCM().viridis(50) % 获取名为viridis的色带的50个数值
% 配合colormap函数使用:
% colormap(PYCM().pink())
% -----------------------------------------------------
% 获取全部colormaps名称:
% PYCM().colormaps()
% -----------------------------------------------------
% 色卡展示:
% PYCM().show() % 创建6个窗口展示全部色卡
% PYCM().show(1) % 展示第一个色卡
pyData=load('PYCMset.mat');
% 获取n个插值颜色基础函数--------------------------------------------------
function map=interpColor(map,n)
if isempty(n)
n=100;
else
if isempty(n{1})||round(n{1}(1))==0||~isnumeric(n{1})
n=100;
else
n=abs(round(n{1}(1)));
end
end
map=map./255;
Xi=1:size(map,1);Xq=linspace(1,size(map,1),n);
map=[interp1(Xi,map(:,1),Xq,'linear')',...
interp1(Xi,map(:,2),Xq,'linear')',...
interp1(Xi,map(:,3),Xq,'linear')'];
end
for i=1:length(pyData.CLASS.Total)
CM.(pyData.CLASS.Total{i})=@(varargin)interpColor(pyData.CM.(pyData.CLASS.Total{i}),varargin);
end
% 展示全部颜色种类函数-----------------------------------------------------
function showName(pyData)
fprintf('%s\n',char(ones(1,60).*61))
for m=1:length(pyData.CLASS.ListFullName)
fprintf('【%s】:\n\n',pyData.CLASS.ListFullName{m})
k6=ceil(length(pyData.CLASS.(pyData.CLASS.List{m}))/6);
for n=1:k6
fprintf('%s ',pyData.CLASS.(pyData.CLASS.List{m}){(n-1)*6+1:min(n*6,end)})
fprintf('\n')
end
fprintf('%s\n',char(ones(1,60).*45))
end
end
CM.colormaps=@()showName(pyData);
% 色卡生成函数-------------------------------------------------------------
function showCM(pyData,n)
if isempty(n)||round(n{1}(1))>6||round(n{1}(1))
关注
打赏