中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么使用Matlab繪制花里胡哨的山脊圖

發布時間:2023-02-24 15:36:33 來源:億速云 閱讀:157 作者:iii 欄目:開發技術

這篇“怎么使用Matlab繪制花里胡哨的山脊圖”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“怎么使用Matlab繪制花里胡哨的山脊圖”文章吧。

    繪制效果如下:

    怎么使用Matlab繪制花里胡哨的山脊圖

    怎么使用Matlab繪制花里胡哨的山脊圖

    怎么使用Matlab繪制花里胡哨的山脊圖

    依舊工具函數放在文末。

    教程部分

    0 數據準備

    X1=normrnd(2,2,1,50);
    X2=[normrnd(4,4,1,50),normrnd(5,2,1,50)];
    X3=[normrnd(6,2,1,50),normrnd(8,4,1,50)];
    X4=[normrnd(12,1,1,50),normrnd(12,4,1,50)];
    X5=[normrnd(10,2,1,50),normrnd(10,4,1,50)];
    X6=[normrnd(7,2,1,50),normrnd(7,4,1,50)];
    X7=[normrnd(4,2,1,50),normrnd(4,4,1,50)];
    
    Data={X1,X2,X3,X4,X5,X6,X7};

    數據為多個一維向量放在元胞數組中,大概像這樣:

    1 基礎繪制:上色類型

    通過設置ColorMode屬性設置上色方式,可設置為:

    • Order

    • X

    • GlobalX

    • Kdensity

    • Qt

    Qt Order:每個山脊不同顏色

    JP=joyPlot(Data,'ColorMode','Order');
    JP=JP.draw();

    怎么使用Matlab繪制花里胡哨的山脊圖

    繪制并添加圖例(同時可以通過MedLine設置顯示中位線):

    JP=joyPlot(Data,'ColorMode','Order','MedLine','on');
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)

    怎么使用Matlab繪制花里胡哨的山脊圖

    可以通過設置ColorList屬性或者使用setPatchColor函數設置顏色,推薦前者:

    ColorList屬性設置顏色:

    newColorList=[0.1059    0.6196    0.4667
        0.8510    0.3725    0.0078
        0.4588    0.4392    0.7020
        0.6529    0.4059    0.3294
        0.9020    0.6706    0.0078
        0.6510    0.4627    0.1137
        0.4000    0.4000    0.4000];
    JP=joyPlot(Data,'ColorMode','Order','ColorList',newColorList);
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)

    怎么使用Matlab繪制花里胡哨的山脊圖

    setPatchColor函數設置顏色,只能設置面顏色設置不了線條顏色:

    JP=joyPlot(Data,'ColorMode','Order');
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)
    
    % 設置山脊顏色
    newColorList=[0.1059    0.6196    0.4667
        0.8510    0.3725    0.0078
        0.4588    0.4392    0.7020
        0.6529    0.4059    0.3294
        0.9020    0.6706    0.0078
        0.6510    0.4627    0.1137
        0.4000    0.4000    0.4000];
    JP=JP.setPatchColor(newColorList)

    怎么使用Matlab繪制花里胡哨的山脊圖

    當然可以全部設置為同一顏色:

    JP=joyPlot(Data,'ColorMode','Order','ColorList',[0,0,.6]);
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl(1))

    怎么使用Matlab繪制花里胡哨的山脊圖

    X 每個山脊分別把X映射為顏色

    JP=joyPlot(Data,'ColorMode','X','MedLine','on');
    JP=JP.draw();

    怎么使用Matlab繪制花里胡哨的山脊圖

    當然可以添加colorbar:

    colorbar()

    怎么使用Matlab繪制花里胡哨的山脊圖

    設置為其他顏色:

    JP=JP.setPatchColor(winter);

    怎么使用Matlab繪制花里胡哨的山脊圖

    JP=JP.setPatchColor(colorcube(256));

    怎么使用Matlab繪制花里胡哨的山脊圖

    GlobalX 全局性把X坐標映射為顏色

    Data={X1,X2,X3,X4,X5,X6,X7};
    JP=joyPlot(Data,'ColorMode','GlobalX','MedLine','on');
    JP=JP.draw();
    
    colorbar

    怎么使用Matlab繪制花里胡哨的山脊圖

    換成別的顏色:

    JP=JP.setPatchColor(colorcube(256));

    怎么使用Matlab繪制花里胡哨的山脊圖

    Kdensity 依靠核密度

    Data={X1,X2,X3,X4,X5,X6,X7};
    JP=joyPlot(Data,'ColorMode','Kdensity','MedLine','on');
    JP=JP.draw();
    
    colorbar

    怎么使用Matlab繪制花里胡哨的山脊圖

    換成別的顏色:

    JP=JP.setPatchColor(turbo);

    怎么使用Matlab繪制花里胡哨的山脊圖

    Qt 分位染色

    默認是0.25,0.75分位染色:

    JP=joyPlot(Data,'ColorMode','Qt','MedLine','on');
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)

    怎么使用Matlab繪制花里胡哨的山脊圖

    修改分位線(通過設置Quantiles屬性):

    JP=joyPlot(Data,'ColorMode','Qt','MedLine','on','Quantiles',[.1,.9]);
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)

    怎么使用Matlab繪制花里胡哨的山脊圖

    繪制分位線(可將QtLine設置為on):

    JP=joyPlot(Data,'ColorMode','Qt','MedLine','on','Quantiles',[.1,.9],'QtLine','on');
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)

    怎么使用Matlab繪制花里胡哨的山脊圖

    值得一提的是,所有染色方式都可以繪制QtLine分位線:

    JP=joyPlot(Data,'ColorMode','Order','MedLine','on','Quantiles',[.1,.9],'QtLine','on');
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)

    怎么使用Matlab繪制花里胡哨的山脊圖

    更多分位線和更豐富配色:

    JP=joyPlot(Data,'ColorMode','Qt','MedLine','on','Quantiles',[.1,.25,.75,.9],'ColorList',turbo(5),'QtLine','on');
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl,{'0~0.1','0.1~0.25','0.25~0.75','0.75~0.9','0.9~1'})

    怎么使用Matlab繪制花里胡哨的山脊圖

    更改配色:

    JP=JP.setPatchColor(bone(6));

    怎么使用Matlab繪制花里胡哨的山脊圖

    2 山脊圖間距

    通過設置Sep屬性設置間距,例如小間距:

    JP=joyPlot(Data,'ColorMode','Kdensity','Sep',1/30);
    JP=JP.draw();
    
    colorbar

    怎么使用Matlab繪制花里胡哨的山脊圖

    間距設置為1/60:

    怎么使用Matlab繪制花里胡哨的山脊圖

    設置大間距(1/3):

    怎么使用Matlab繪制花里胡哨的山脊圖

    3 繪制線狀散點

    只有Order類型配色不是黑色:

    JP=joyPlot(Data,'ColorMode','Order','Scatter','on');
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl

    怎么使用Matlab繪制花里胡哨的山脊圖

    Data={X1,X2,X3,X4,X5,X6,X7};
    JP=joyPlot(Data,'ColorMode','GlobalX','MedLine','on','Scatter','on');
    JP=JP.draw();
    
    colorbar

    怎么使用Matlab繪制花里胡哨的山脊圖

    4 屬性單獨設置

    每個玩意的屬性都可以單獨設置

    例如:

    • setRidgePatch 設置山脊面

    • setRidgeLine 設置山脊邊緣線

    • setMedLine 設置中位線

    • setQtLine 設置分位線

    • setScatter 設置散點

    JP=joyPlot(Data,'ColorMode','Order','Scatter','on','QtLine','on','MedLine','on','Sep',1/5);
    JP=JP.draw();
    
    legendHdl=JP.getLegendHdl();
    legend(legendHdl)

    怎么使用Matlab繪制花里胡哨的山脊圖

    設置第3個山脊顏色和透明度:

    JP.setRidgePatch(3,'FaceColor',[0,0,0],'FaceAlpha',.5)

    怎么使用Matlab繪制花里胡哨的山脊圖

    循環改變所有的顏色和透明度:

    for i=1:length(Data)
        JP.setRidgePatch(i,'FaceColor',[1,1,1]./length(Data).*i,'FaceAlpha',.5)
    end

    怎么使用Matlab繪制花里胡哨的山脊圖

    其他玩意也都類似!

    for i=1:length(Data)
        JP.setRidgePatch(i,'FaceColor',[1,1,1]./length(Data).*i,'FaceAlpha',.5)
        JP.setRidgeLine(i,'Color',[0,0,.8],'LineWidth',1)
        JP.setScatter(i,'Color',[0,0,0,.4])
        JP.setMedLine(i,'Color',[0,0,.8])
        JP.setQtLine(i,'Color',[0,0,.8])
    end

    怎么使用Matlab繪制花里胡哨的山脊圖

    5 多組數據繪圖

    舉個例子:

    X1_1=normrnd(-15,2,1,20);
    X1_2=[normrnd(4,4,1,10),normrnd(5,2,1,10)];
    X1_3=[normrnd(6,2,1,10),normrnd(8,4,1,10)];
    X1_4=[normrnd(12,1,1,10),normrnd(12,4,1,10)];
    X1_5=[normrnd(-7,2,1,10),normrnd(2,4,1,10)];
    X1_6=[normrnd(-7,2,1,10),normrnd(-7,4,1,10)];
    Data1={X1_1,X1_2,X1_3,X1_4,X1_5,X1_6};
    X2_1=normrnd(-8,2,1,20);
    X2_2=[normrnd(2,4,1,10),normrnd(2,2,1,10)];
    X2_3=[normrnd(18,2,1,10),normrnd(18,4,1,10)];
    X2_4=[normrnd(18,1,1,10),normrnd(18,4,1,10)];
    X2_5=[normrnd(5,2,1,10),normrnd(5,4,1,10)];
    X2_6=[normrnd(-20,2,1,10),normrnd(-20,4,1,10)];
    Data2={X2_1,X2_2,X2_3,X2_4,X2_5,X2_6};
    
    JP1=joyPlot(Data1,'ColorMode','Order','ColorList',[12,165,154]./255,'MedLine','on','Scatter','on');
    JP1=JP1.draw();
    
    JP2=joyPlot(Data2,'ColorMode','Order','ColorList',[151,220,71]./255,'MedLine','on','Scatter','on');
    JP2=JP2.draw();
    
    
    % 設置中位線顏色
    for i=1:length(Data1)
        JP1.setMedLine(i,'Color',[12,165,154]./255)
    end
    for i=1:length(Data2)
        JP2.setMedLine(i,'Color',[151,220,71]./255)
    end
    
    % 繪制圖例
    legendHdl1=JP1.getLegendHdl();
    legendHdl2=JP2.getLegendHdl();
    legend([legendHdl1(1),legendHdl2(1)],{'AAAAA','BBBBB'})

    怎么使用Matlab繪制花里胡哨的山脊圖

    工具函數完整代碼

    classdef joyPlot
    % @author : slandarer
    % gzh  : slandarer隨筆 
    % Zhaoxu Liu / slandarer (2023). joyplot 
    % (https://www.mathworks.com/matlabcentral/fileexchange/125255-joyplot), 
    % MATLAB Central File Exchange. 檢索來源 2023/2/23.
        properties
            ax,arginList={'ColorMode','ColorList','Sep','Scatter','MedLine','Quantiles','QtLine'}
            ColorMode='Order'   % 上色模式'Order'/'X'/'GlobalX'/'Kdensity'/'Qt'
            ColorList
            defaultColorList1=[0.3725    0.2745    0.5647;    0.1137    0.4118    0.5882;    0.2196    0.6510    0.6471;    0.0588    0.5216    0.3294
                               0.4510    0.6863    0.2824;    0.9294    0.6784    0.0314;    0.8824    0.4863    0.0196;    0.8000    0.3137    0.2431
                               0.5804    0.2039    0.4314;    0.4353    0.2510    0.4392];
            defaultColorList2=[0.0015    0.0005    0.0139;    0.0143    0.0122    0.0705;    0.0415    0.0323    0.1373;    0.0773    0.0535    0.2088;    
                               0.1179    0.0664    0.2854;    0.1661    0.0678    0.3630;    0.2209    0.0609    0.4276;    0.2758    0.0616    0.4677;    
                               0.3279    0.0755    0.4889;    0.3784    0.0954    0.5001;    0.4284    0.1160    0.5058;    0.4788    0.1357    0.5080;    
                               0.5297    0.1541    0.5070;    0.5814    0.1715    0.5028;    0.6338    0.1882    0.4951;    0.6867    0.2051    0.4836;    
                               0.7395    0.2231    0.4679;    0.7914    0.2438    0.4480;    0.8410    0.2692    0.4245;    0.8861    0.3019    0.3992;    
                               0.9240    0.3441    0.3761;    0.9524    0.3958    0.3617;    0.9715    0.4540    0.3610;    0.9837    0.5147    0.3747;    
                               0.9912    0.5758    0.4003;    0.9954    0.6364    0.4350;    0.9972    0.6964    0.4765;    0.9971    0.7559    0.5234;    
                               0.9956    0.8150    0.5747;    0.9930    0.8739    0.6300;    0.9899    0.9327    0.6886;    0.9871    0.9914    0.7495];
            defaultColorList3=[255,153,154;220,220,220;153,153,253]./255;
            Sep=1/8;          % 兩個山脊間距離
            Scatter='off';    % 是否繪制豎線狀散點
            MedLine='off';
            QtLine='off';
            Quantiles=[.25,.75];QtX,QtY
            ridgeNum,Data,minX,maxX,maxY,XiSet,FSet
            ridgePatchHdl,ridgeLineHdl
            medLineHdl,scatterHdl;QtLineHdl;QtLegendHdl
        end
    
        methods
            function obj=joyPlot(Data,varargin)
                obj.Data=Data;
                obj.ridgeNum=length(obj.Data);
    
                % 獲取其他數據
                disp(char([64 97 117 116 104 111 114 32 58 32,...
                     115 108 97 110 100 97 114 101 114]))
                for i=1:2:(length(varargin)-1)
                    tid=ismember(obj.arginList,varargin{i});
                    if any(tid)
                        obj.(obj.arginList{tid})=varargin{i+1};
                    end
                end
                if isempty(intersect(obj.ColorMode,{'Order','X','GlobalX','Kdensity','Qt'}))
                    error('The ColorMode should be one of the following: Order \ X \ GlobalX \ Kdensity \ Qt')
                end
                switch obj.ColorMode
                    case 'Order',obj.ColorList=obj.defaultColorList1;
                    case 'X',obj.ColorList=obj.defaultColorList2;
                    case 'GlobalX',obj.ColorList=obj.defaultColorList2;
                    case 'Kdensity',obj.ColorList=obj.defaultColorList2;
                    case 'Qt',obj.ColorList=obj.defaultColorList3;
                end
                for i=1:2:(length(varargin)-1)
                    tid=ismember(obj.arginList,varargin{i});
                    if any(tid)
                        obj.(obj.arginList{tid})=varargin{i+1};
                    end
                end
                obj.minX=min(obj.Data{1});
                obj.maxX=max(obj.Data{1});
                for i=1:obj.ridgeNum
                    obj.minX=min(obj.minX,min(obj.Data{i}));
                    obj.maxX=max(obj.maxX,max(obj.Data{i}));
                end
            end
            function obj=draw(obj)
                obj.ax=gca;hold on;
                obj.ax.LineWidth=1;
                obj.ax.YTick=(1:obj.ridgeNum).*obj.Sep;
                obj.ax.FontName='Cambria';
                obj.ax.FontSize=13;
                obj.ax.YGrid='on';
                % obj.ax.Box='on';
                obj.ax.TickDir='out';
                tYLabel{obj.ridgeNum}='';
                for i=1:obj.ridgeNum
                    tYLabel{i}=['Class-',num2str(i)];
                end
                obj.ax.YTickLabel=tYLabel;
    
                % 調整初始界面大小
                fig=obj.ax.Parent;
                fig.Color=[1,1,1];
                if max(fig.Position(3:4))<690
                    fig.Position(3:4)=1.2.*fig.Position(3:4);
                    fig.Position(1:2)=fig.Position(1:2)./2;
                end
    
                % 繪制patch圖像
                obj.minX=min(obj.Data{1});
                obj.maxX=max(obj.Data{1});
                obj.maxY=0;
                for i=1:obj.ridgeNum
                    tX=obj.Data{i};tX=tX(:)';
                    [F,Xi]=ksdensity(tX);
                    obj.minX=min(obj.minX,min(Xi));
                    obj.maxX=max(obj.maxX,max(Xi));
                    obj.maxY=max(obj.maxY,max(F));
                end
                for i=obj.ridgeNum:-1:1
                    tX=obj.Data{i};tX=tX(:)';
                    [F,Xi]=ksdensity(tX);
                    OXi=Xi;
                    Xi=linspace(min(Xi),max(Xi),1000);
                    F=interp1(OXi,F,Xi);
                    obj.XiSet{i}=Xi;
                    obj.FSet{i}=F;
                    % 繪制豎線散點
                    tXX=[tX;tX;tX.*nan];
                    tYY=[tX.*0+obj.Sep.*i-obj.Sep./10;tX.*0+obj.Sep.*i-obj.Sep./2.5;tX.*nan];
                    if isequal(obj.ColorMode,'Order')
                        obj.scatterHdl(i)=plot(tXX(:),tYY(:),'Color',[obj.ColorList(mod(i-1,size(obj.ColorList,1))+1,:),.5],'LineWidth',.8,'Visible','off');
                    else
                        obj.scatterHdl(i)=plot(tXX(:),tYY(:),'Color',[0,0,0,.5],'LineWidth',.8,'Visible','off');
                    end
                    if isequal(obj.Scatter,'on'),set(obj.scatterHdl(i),'Visible','on');end
                    % 計算分位線
                    for j=1:length(obj.Quantiles)
                        obj.QtX(i,j+1)=quantile(tX,obj.Quantiles(j));
                        obj.QtY(i,j)=interp1(Xi,F,quantile(tX,obj.Quantiles(j)));
                    end
                    obj.QtX(i,1)=min(Xi)-inf;
                    obj.QtX(i,length(obj.Quantiles)+2)=max(Xi)+inf;
                    switch obj.ColorMode
                        case 'Order'
                            obj.ridgePatchHdl(i)=fill([Xi(1),Xi,Xi(end)],[0,F,0]+obj.Sep.*(i).*ones(1,length(F)+2),...
                                obj.ColorList(mod(i-1,size(obj.ColorList,1))+1,:),'EdgeColor','none','FaceAlpha',.5);
                            obj.ridgeLineHdl(i)=plot([Xi(1),Xi,Xi(end)],[0,F,0]+obj.Sep.*(i).*ones(1,length(F)+2),...
                                'Color',obj.ColorList(mod(i-1,size(obj.ColorList,1))+1,:),'LineWidth',.8);
                            colormap(obj.ColorList);
                            try caxis([1,obj.ridgeNum]),catch,end
                            try clim([1,obj.ridgeNum]),catch,end
                        case 'X'
                            tTi=[Xi(1),Xi,Xi(end),Xi(end:-1:1)]-min(Xi);tTi=tTi./max(tTi);
                            tT=linspace(0,1,size(obj.ColorList,1));
                            tC=cat(3,interp1(tT,obj.ColorList(:,1),tTi),interp1(tT,obj.ColorList(:,2),tTi),interp1(tT,obj.ColorList(:,3),tTi));
                            obj.ridgePatchHdl(i)=fill([Xi(1),Xi,Xi(end),Xi(end:-1:1)],[0,F,0,F.*0]+obj.Sep.*(i).*ones(1,length(F)*2+2),...
                                tC,'EdgeColor','none','FaceAlpha',.9,'FaceColor','interp');
                            obj.ridgeLineHdl(i)=plot([Xi(1),Xi,Xi(end)],[0,F,0]+obj.Sep.*(i).*ones(1,length(F)+2),...
                                'Color',[0,0,0,.9],'LineWidth',.8);
                            colormap(obj.ColorList);
                            try caxis([-1,1]),catch,end
                            try clim([-1,1]),catch,end
                        case 'GlobalX'
                            tTi=[Xi(1),Xi,Xi(end),Xi(end:-1:1)]-obj.minX;
                            tTi=tTi./(obj.maxX-obj.minX);
                            tT=linspace(0,1,size(obj.ColorList,1));
                            tC=cat(3,interp1(tT,obj.ColorList(:,1),tTi),interp1(tT,obj.ColorList(:,2),tTi),interp1(tT,obj.ColorList(:,3),tTi));
                            obj.ridgePatchHdl(i)=fill([Xi(1),Xi,Xi(end),Xi(end:-1:1)],[0,F,0,F.*0]+obj.Sep.*(i).*ones(1,length(F)*2+2),...
                                tC,'EdgeColor','none','FaceAlpha',.9,'FaceColor','interp');
                            obj.ridgeLineHdl(i)=plot([Xi(1),Xi,Xi(end)],[0,F,0]+obj.Sep.*(i).*ones(1,length(F)+2),...
                                'Color',[0,0,0,.9],'LineWidth',.8);
                            colormap(obj.ColorList);
                            try caxis([obj.minX,obj.maxX]),catch,end
                            try clim([obj.minX,obj.maxX]),catch,end
                        case 'Kdensity'
                            tTi=[0,F,0,F(end:-1:1)];
                            tTi=tTi./obj.maxY;
                            tT=linspace(0,1,size(obj.ColorList,1));
                            tC=cat(3,interp1(tT,obj.ColorList(:,1),tTi),interp1(tT,obj.ColorList(:,2),tTi),interp1(tT,obj.ColorList(:,3),tTi));
                            obj.ridgePatchHdl(i)=fill([Xi(1),Xi,Xi(end),Xi(end:-1:1)],[0,F,0,F.*0]+obj.Sep.*(i).*ones(1,length(F)*2+2),...
                                tC,'EdgeColor','none','FaceAlpha',.9,'FaceColor','interp');
                            obj.ridgeLineHdl(i)=plot([Xi(1),Xi,Xi(end)],[0,F,0]+obj.Sep.*(i).*ones(1,length(F)+2),...
                                'Color',[0,0,0,.9],'LineWidth',.8);
                            colormap(obj.ColorList);
                            try caxis([0,obj.maxY]),catch,end
                            try clim([0,obj.maxY]),catch,end
                        case 'Qt'
                            tTi=[Xi(1),Xi,Xi(end),Xi(end:-1:1)];
                            tR=tTi.*0;tG=tTi.*0;tB=tTi.*0;
                            for j=1:size(obj.QtX,2)-1
                                tR(tTi>=obj.QtX(i,j)&tTi<obj.QtX(i,j+1))=obj.ColorList(mod(j-1,size(obj.ColorList,1))+1,1);
                                tG(tTi>=obj.QtX(i,j)&tTi<obj.QtX(i,j+1))=obj.ColorList(mod(j-1,size(obj.ColorList,1))+1,2);
                                tB(tTi>=obj.QtX(i,j)&tTi<obj.QtX(i,j+1))=obj.ColorList(mod(j-1,size(obj.ColorList,1))+1,3);
                            end
                            tC=cat(3,tR,tG,tB);
                            obj.ridgePatchHdl(i)=fill([Xi(1),Xi,Xi(end),Xi(end:-1:1)],[0,F,0,F.*0]+obj.Sep.*(i).*ones(1,length(F)*2+2),...
                                tC,'EdgeColor','none','FaceAlpha',.9,'FaceColor','interp');
                            obj.ridgeLineHdl(i)=plot([Xi(1),Xi,Xi(end)],[0,F,0]+obj.Sep.*(i).*ones(1,length(F)+2),...
                                'Color',[0,0,0,.9],'LineWidth',.8);
                            colormap(obj.ColorList);
                            try caxis([-1,1]),catch,end
                            try clim([-1,1]),catch,end
                    end
                    % 繪制中位線
                    tMedX=median(tX);
                    tMedY=interp1(Xi,F,tMedX);
                    obj.medLineHdl(i)=plot([tMedX,tMedX],[0,tMedY]++obj.Sep.*[i,i],'LineStyle','--','LineWidth',1,'Color',[0,0,0],'Visible','off'); 
                    if isequal(obj.MedLine,'on'),set(obj.medLineHdl(i),'Visible','on');end
                    % 繪制分位線
                    tQtY=[obj.QtY(i,:);obj.QtY(i,:).*0;obj.QtY(i,:).*nan]+obj.Sep.*i;
                    tQtX=[obj.QtX(i,2:end-1);obj.QtX(i,2:end-1);obj.QtX(i,2:end-1).*nan];
                    obj.QtLineHdl(i)=plot(tQtX(:),tQtY(:),'LineWidth',1,'Color',[0,0,0,.8],'Visible','off');
                    if isequal(obj.QtLine,'on'),set(obj.QtLineHdl(i),'Visible','on');end
                    % % 繪制25,75分位線
                    % tQt25X=quantile(tX,0.25);
                    % tQt75X=quantile(tX,0.75);
                    % tQt25Y=interp1(Xi,F,tQt25X);
                    % tQt75Y=interp1(Xi,F,tQt75X);
                    % obj.qt25LineHdl(i)=plot([tQt25X,tQt25X],[0,tQt25Y]+obj.Sep.*[i,i],'LineWidth',1,'Color',[1,1,1,.8],'Visible','off');
                    % obj.qt75LineHdl(i)=plot([tQt75X,tQt75X],[0,tQt75Y]+obj.Sep.*[i,i],'LineWidth',1,'Color',[1,1,1,.8],'Visible','off');
                    % if isequal(obj.QT25Line,'on'),set(obj.qt25LineHdl(i),'Visible','on');end
                    % if isequal(obj.QT75Line,'on'),set(obj.qt75LineHdl(i),'Visible','on');end
                end
                axis tight
                obj.ax.YLim(1)=obj.Sep/2;
                for i=1:size(obj.QtX,2)-1
                    obj.QtLegendHdl(i)=fill(mean(obj.ax.XLim).*[1,1,1,1],mean(obj.ax.YLim).*[1,1,1,1],...
                        obj.ColorList(mod(i-1,size(obj.ColorList,1))+1,:),'EdgeColor','none','FaceAlpha',.9);
                end
            end
            % 獲取繪制圖例對象
            function legendHdl=getLegendHdl(obj)
                if isequal(obj.ColorMode,'Qt')
                    legendHdl=obj.QtLegendHdl;
                else
                    legendHdl=obj.ridgePatchHdl;
                end
            end
            % 顏色重設置
            function obj=setPatchColor(obj,ColorList)
                obj.ColorList=ColorList;
                colormap(obj.ColorList);
                for i=obj.ridgeNum:-1:1
                    Xi=obj.XiSet{i};
                    F=obj.FSet{i};
                    switch obj.ColorMode
                        case 'Order'
                            set(obj.ridgePatchHdl(i),'FaceColor',obj.ColorList(mod(i-1,size(obj.ColorList,1))+1,:));
                        case 'X'
                            tTi=[Xi(1),Xi,Xi(end),Xi(end:-1:1)]-min(Xi);tTi=tTi./max(tTi);
                            tT=linspace(0,1,size(obj.ColorList,1));
                            tC=cat(3,interp1(tT,obj.ColorList(:,1),tTi),interp1(tT,obj.ColorList(:,2),tTi),interp1(tT,obj.ColorList(:,3),tTi));
                            set(obj.ridgePatchHdl(i),'CData',tC);
                        case 'GlobalX'
                            tTi=[Xi(1),Xi,Xi(end),Xi(end:-1:1)]-obj.minX;
                            tTi=tTi./(obj.maxX-obj.minX);
                            tT=linspace(0,1,size(obj.ColorList,1));
                            tC=cat(3,interp1(tT,obj.ColorList(:,1),tTi),interp1(tT,obj.ColorList(:,2),tTi),interp1(tT,obj.ColorList(:,3),tTi));
                            set(obj.ridgePatchHdl(i),'CData',tC);
                        case 'Kdensity'
                            tTi=[0,F,0,F(end:-1:1)];
                            tTi=tTi./obj.maxY;
                            tT=linspace(0,1,size(obj.ColorList,1));
                            tC=cat(3,interp1(tT,obj.ColorList(:,1),tTi),interp1(tT,obj.ColorList(:,2),tTi),interp1(tT,obj.ColorList(:,3),tTi));
                            set(obj.ridgePatchHdl(i),'CData',tC);
                        case 'Qt'
                            tTi=[Xi(1),Xi,Xi(end),Xi(end:-1:1)];
                            tR=tTi.*0;tG=tTi.*0;tB=tTi.*0;
                            for j=1:size(obj.QtX,2)-1
                                tR(tTi>=obj.QtX(i,j)&tTi<obj.QtX(i,j+1))=obj.ColorList(mod(j-1,size(obj.ColorList,1))+1,1);
                                tG(tTi>=obj.QtX(i,j)&tTi<obj.QtX(i,j+1))=obj.ColorList(mod(j-1,size(obj.ColorList,1))+1,2);
                                tB(tTi>=obj.QtX(i,j)&tTi<obj.QtX(i,j+1))=obj.ColorList(mod(j-1,size(obj.ColorList,1))+1,3);
                            end
                            tC=cat(3,tR,tG,tB);
                            set(obj.ridgePatchHdl(i),'CData',tC);
                    end
                end
                for i=1:size(obj.QtX,2)-1
                    set(obj.QtLegendHdl(i),'FaceColor',obj.ColorList(mod(i-1,size(obj.ColorList,1))+1,:));
                end
            end
            % 設置Patch及Line對象其他屬性
            function setRidgePatch(obj,n,varargin)
                set(obj.ridgePatchHdl(n),varargin{:})
            end
            function setRidgeLine(obj,n,varargin)
                set(obj.ridgeLineHdl(n),varargin{:})
            end
            % 設置各個分位線屬性
            function setMedLine(obj,n,varargin)
                set(obj.medLineHdl(n),varargin{:})
            end
            function setQtLine(obj,n,varargin)
                set(obj.QtLineHdl(n),varargin{:})
            end
            % 設置scatter屬性
            function setScatter(obj,n,varargin)
                set(obj.scatterHdl(n),varargin{:})
            end
        end
    % @author : slandarer
    % gzh  : slandarer隨筆 
    % Zhaoxu Liu / slandarer (2023). joyplot 
    % (https://www.mathworks.com/matlabcentral/fileexchange/125255-joyplot), 
    % MATLAB Central File Exchange. 檢索來源 2023/2/23.
    end

    以上就是關于“怎么使用Matlab繪制花里胡哨的山脊圖”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。

    向AI問一下細節

    免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

    AI

    寿阳县| 宣威市| 营山县| 开化县| 榕江县| 博爱县| 敖汉旗| 宁陕县| 上虞市| 凌海市| 黑龙江省| 宽城| 若尔盖县| 沂源县| 沭阳县| 河北区| 赫章县| 沁源县| 青神县| 镇沅| 哈尔滨市| 腾冲县| 安多县| 邮箱| 寻甸| 德化县| 玉林市| 日喀则市| 绥阳县| 且末县| 文水县| 家居| 阿鲁科尔沁旗| 巨野县| 扎兰屯市| 土默特右旗| 志丹县| 龙口市| 喀喇沁旗| 德江县| 齐齐哈尔市|