美文网首页
【研究工具】Matlab画带状图函数

【研究工具】Matlab画带状图函数

作者: 子夜Uni | 来源:发表于2022-08-08 15:33 被阅读0次

    整理了一个画带状图(Ribbon)的函数。

    
    % function: drawRibbon-Draw Ribbon Plot for Given Data (average & confidence interval)
    %
    % input paras
    % arrData: average data of each group; size[m(length of each group)*n(number of group);
    % arrConfData: confidence data of each group; size[m(length of each group)*n(number of group);
    % cellColor: color of each group;
    % cellGroupNames: legend for each group;
    % alphaRibbon: alpha of the Ribbon;
    
    
    
    function drawRibbon(arrData,arrConfData,cellColor,cellGroupNames,alphaRibbon)
        
    
        [dataLength, numGroup] = size(arrData);
        xData =1:dataLength;
    
    
        % calculate  upper & lower limit for filled area and draw
    
        for indGroup = 1 : numGroup
            arrUpper = arrData(:,indGroup) + arrConfData(:,indGroup);
            arrLower = arrData(:,indGroup) - arrConfData(:,indGroup);
    
            fill([xData xData(end:-1:1)],[arrUpper' arrLower(end:-1:1)'],'k','FaceColor',cellColor{indGroup},'FaceAlpha',alphaRibbon,'EdgeColor','none')
            hold on;
            
        end
    
        % draw average data
        
        for indGroup = 1 : numGroup
        
            arrFig(indGroup) = plot(xData,arrData(:,indGroup),'-','Color',cellColor{indGroup},'lineWidth',1,'markersize',10);
            hold on;
        end
         
    %     xlabel('xlabel','FontSize',12);
    %     ylabel('ylabel','FontSize',12);
    %     axis([0 0 0 0]);
    
        legend(arrFig,cellGroupNames);
        hold off;
    
    end
    
    

    使用示例

    figure(1);
    drawRibbon([meanHappy meanSad],[confHappy confSad],{[192/255,44/255,56/255],[122/255,115/255,116/255]},{'Happy','Sad'},0.3);
    
    

    示例效果


    示例效果

    相关文章

      网友评论

          本文标题:【研究工具】Matlab画带状图函数

          本文链接:https://www.haomeiwen.com/subject/doenwrtx.html