亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于Matlab實(shí)現(xiàn)山脊圖的繪制

 更新時(shí)間:2022年05月10日 09:22:27   作者:slandarer  
這篇文章主要介紹了如何利用Matlab實(shí)現(xiàn)山脊圖的繪制,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Matlab有一定的幫助,需要的可以參考一下

寫了一個(gè)用于繪制山脊圖的模板,僅需要往需要填寫數(shù)據(jù)的區(qū)域填入數(shù)據(jù)點(diǎn)擊運(yùn)行即可,以下提供兩款模板,第一款為純色模板而第二款為漸變色模板:

純色山脊圖模板

模板代碼:

function ridgeMapTMPL1
% @author: slandarer

% 在這里放入你的數(shù)據(jù)=======================================================
X1=normrnd(2,2,1,1000);
X2=[normrnd(4,4,1,1000),normrnd(5,2,1,200)];
X3=[normrnd(2.5,2,1,1000),normrnd(6,4,1,200)];
X4=[normrnd(1,1,1,300),normrnd(2,4,1,200)];
X5=[normrnd(4,2,1,300),normrnd(2,4,1,600)];

% 把數(shù)據(jù)放到元胞數(shù)組,要是數(shù)據(jù)太多可寫循環(huán)放入
dataCell={X1,X2,X3,X4,X5};    

% 各個(gè)數(shù)據(jù)類的名稱,可空著
dataName={'A','B','C','D','E'};

% 各個(gè)山脊的顏色,可空著也可只放一個(gè)顏色
colorList=[];                  

% 非必要屬性
% -------------------------------------------------------------------------
legendOn=false;  % 是否繪制圖例 true/false
xTickOn=true;    % 開(kāi)啟X軸

sep=1/6;         % 設(shè)置山脊距離,可空著
xLim=[];         % 設(shè)置X軸范圍距離,可空著
axColor=[];      % 設(shè)置背景顏色,可空著
fontName='';     % 設(shè)置X,Y軸標(biāo)簽字體,可空著
fontSize=14;     % 設(shè)置X,Y軸標(biāo)簽字號(hào),可空著
faceAlpha=1;           % 面透明度
edgeColor=[1,1,1].*.3; % 邊緣顏色
% =========================================================================

% 設(shè)置顏色
classNum=length(dataCell);
if size(colorList,1)==0
    colorList=repmat([130,170,172]./255,[classNum,1]);
else
    colorList=repmat(colorList,[ceil(classNum/size(colorList,1)),1]);
end

% 設(shè)置間隙距離
if isempty(sep)
sep=1/6;
end

hold on
ax=gca;
ax.YGrid='on';
ax.YLim=[0,sep*classNum+sep/2];
ax.YTick=0:sep:sep*(classNum-1);
ax.YColor='none';
ax.LineWidth=1.2;
% ax.YTickLabel=dataName;
if isempty(fontName),fontName='Helvetica';end
if isempty(fontSize),fontSize=14;end
ax.FontName=fontName;
ax.FontSize=fontSize;
if ~xTickOn,ax.XColor='none';end
if ~isempty(xLim),ax.XLim=xLim;end
if ~isempty(axColor),ax.Color=axColor;end
if isempty(dataName)
    for i=1:classNum
        dataName{i}=num2str(i);
    end
end

% 繪制山脊
for i=1:classNum
    tX=dataCell{i};tX=tX(:);
    [F,Xi]=ksdensity(tX);
    patchCell(i)=fill([Xi(1),Xi,Xi(end)],[0,F,0]+(sep).*(classNum-i).*ones(1,length(F)+2),...
        colorList(i,:),'EdgeColor','none','FaceAlpha',faceAlpha);
    plot([Xi(1),Xi,Xi(end)],[0,F,0]+(sep).*(classNum-i).*ones(1,length(F)+2),...
        'Color',edgeColor,'LineWidth',1.2)
end

% 繪制圖例
if legendOn
legend(patchCell,dataName)
end

% 繪制字符
ax.UserData.classNum=classNum;
ax.UserData.sep=sep;
for k=1:classNum
    ax.UserData.(['t',num2str(k)])=text(ax.XLim(1),(sep).*(classNum-k),[dataName{k},' '],...
        'FontSize',fontSize,'FontName',fontName,'HorizontalAlignment','right','VerticalAlignment','bottom');
end
    function reTXT(~,~)
        for kk=1:ax.UserData.classNum
            ax.UserData.(['t',num2str(kk)]).Position=...
                [ax.XLim(1),(ax.UserData.sep).*(ax.UserData.classNum-kk),0];
        end
    end

set(ax.Parent,'WindowButtonMotionFcn',@reTXT); 
% 額外的屬性設(shè)置===========================================================
% ax.(...)=...

% =========================================================================
end

繪制效果:

更該部分配置后的繪制效果:

將每個(gè)山脊賦予不同顏色,刪除X軸并添加圖例

% 在這里放入你的數(shù)據(jù)=======================================================
X1=normrnd(2,2,1,1000);
X2=[normrnd(4,4,1,1000),normrnd(5,2,1,200)];
X3=[normrnd(2.5,2,1,1000),normrnd(6,4,1,200)];
X4=[normrnd(1,1,1,300),normrnd(2,4,1,200)];
X5=[normrnd(4,2,1,300),normrnd(2,4,1,600)];

% 把數(shù)據(jù)放到元胞數(shù)組,要是數(shù)據(jù)太多可寫循環(huán)放入
dataCell={X1,X2,X3,X4,X5};    

% 各個(gè)數(shù)據(jù)類的名稱,可空著
dataName={'A','B','C','D','E'};

% 各個(gè)山脊的顏色,可空著也可只放一個(gè)顏色
colorList=[0.98,0.70,0.95
0.69,0.81,1.00
0.50,0.88,0.89
0.50,0.87,0.61
0.86,0.82,0.50];                  

% 非必要屬性
% -------------------------------------------------------------------------
legendOn=true;  % 是否繪制圖例 true/false
xTickOn=false;   % 開(kāi)啟X軸

sep=1/6;         % 設(shè)置山脊距離,可空著
xLim=[];         % 設(shè)置X軸范圍距離,可空著
axColor=[];      % 設(shè)置背景顏色,可空著
fontName=[];     % 設(shè)置X,Y軸標(biāo)簽字體,可空著
fontSize=14;     % 設(shè)置X,Y軸標(biāo)簽字號(hào),可空著
faceAlpha=1;           % 面透明度
edgeColor=[1,1,1].*.3; % 邊緣顏色
% ===============================================================

漸變色山脊圖模板

模板代碼:

function ridgeMapTMPL2
% @author: slandarer

% 在這里放入你的數(shù)據(jù)=======================================================
X1=normrnd(2,2,1,1000);
X2=[normrnd(4,4,1,1000),normrnd(5,2,1,200)];
X3=[normrnd(2.5,2,1,1000),normrnd(6,4,1,200)];
X4=[normrnd(1,1,1,300),normrnd(2,4,1,200)];
X5=[normrnd(4,2,1,300),normrnd(2,4,1,600)];

% 把數(shù)據(jù)放到元胞數(shù)組,要是數(shù)據(jù)太多可寫循環(huán)放入
dataCell={X1,X2,X3,X4,X5};    

% 各個(gè)數(shù)據(jù)類的名稱,可空著
dataName={'A','B','C','D','E'};

% 山脊的漸變顏色,可空著也放數(shù)組也可放顏色名稱
cmap=[];
% cmap=PYCM().plasma();   
% cmap='colorcube'

% 非必要屬性
% -------------------------------------------------------------------------
xTickOn=true;    % 開(kāi)啟X軸

sep=1/6;         % 設(shè)置山脊距離,可空著
xLim=[];         % 設(shè)置X軸范圍距離,可空著
fontName='';     % 設(shè)置X,Y軸標(biāo)簽字體,可空著
fontSize=14;     % 設(shè)置X,Y軸標(biāo)簽字號(hào),可空著
% =========================================================================


classNum=length(dataCell);

% 設(shè)置間隙距離
if isempty(sep)
sep=1/6;
end

hold on
ax=gca;
ax.YGrid='on';
ax.YLim=[0,sep*classNum+sep/2];
ax.YTick=0:sep:sep*(classNum-1);
ax.YColor='none';
ax.LineWidth=1.2;
% ax.YTickLabel=dataName;
if isempty(fontName),fontName='Helvetica';end
if isempty(fontSize),fontSize=14;end

ax.FontName=fontName;
ax.FontSize=fontSize;
if ~xTickOn,ax.XColor='none';end
if ~isempty(xLim),ax.XLim=xLim;end
if isempty(dataName)
    for i=1:classNum
        dataName{i}=num2str(i);
    end
end

% 繪制山脊
for i=1:classNum
    tX=dataCell{i};tX=tX(:);
    [F,Xi]=ksdensity(tX);
    patchCell(i)=patch([Xi(1),Xi,Xi(end)],[0,F,0]+(sep).*(classNum-i).*ones(1,length(F)+2),...
        [Xi(1),Xi,Xi(end)],'FaceColor','interp','EdgeColor','none');
    plot([Xi(1),Xi,Xi(end)],[0,F,0]+(sep).*(classNum-i).*ones(1,length(F)+2),...
        'Color',[.3,.3,.3],'LineWidth',1.2)
end
if isempty(cmap)
colormap()
else
colormap(cmap)
end

% 繪制字符
ax.UserData.classNum=classNum;
ax.UserData.sep=sep;
for k=1:classNum
    ax.UserData.(['t',num2str(k)])=text(ax.XLim(1),(sep).*(classNum-k),[dataName{k},' '],...
        'FontSize',fontSize,'FontName',fontName,'HorizontalAlignment','right','VerticalAlignment','bottom');
end
    function reTXT(~,~)
        for kk=1:ax.UserData.classNum
            ax.UserData.(['t',num2str(kk)]).Position=...
                [ax.XLim(1),(ax.UserData.sep).*(ax.UserData.classNum-kk),0];
        end
    end

set(ax.Parent,'WindowButtonMotionFcn',@reTXT); 
% 額外的屬性設(shè)置===========================================================
% ax.(...)=...

% =========================================================================
end

繪制效果:

使用MATLAB自帶顏色:

例:將cmap=[]改為:

cmap='summer'

cmap='colorcube'

使用PYCM函數(shù):

例:將cmap=[]改為:

cmap=PYCM().plasma()

到此這篇關(guān)于基于Matlab實(shí)現(xiàn)山脊圖的繪制的文章就介紹到這了,更多相關(guān)Matlab山脊圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論