【问题标题】:Plot means over grouped boxplot in MATLAB?绘图意味着MATLAB中的分组箱线图?
【发布时间】:2017-12-19 06:03:37
【问题描述】:

我正在使用 multiple_boxplot 函数来生成分组箱线图: http://au.mathworks.com/matlabcentral/fileexchange/47233-multiple-boxplot-m

但是,我想绘制均值而不是中位数。首先我尝试了通用方法:

plot([mean(x)],'dg'); 

但它没有工作。我试图提取手段然后绘制它们,但这也不起作用。

m=[];
for i=1:max(group) 
idx=find(group==i);
m=[m nanmean(x(idx))];
end

boxplot(x,group, 'positions', positions);hold on 
plot([m],'dg')

我做错了什么?以及如何用每个箱线图绘制均值? 谢谢。

【问题讨论】:

    标签: matlab boxplot


    【解决方案1】:

    您可以执行以下操作:

    在函数 multiple_boxplot 中将第 48 行更改为:

    B = boxplot(x,group, 'positions', positions);
    

    并将函数的标题更改为:

    B = multiple_boxplot(data...
    

    并保存函数文件。

    这不会改变函数的工作方式,但会让您获得箱线图的句柄 (B)。

    然后在您的代码中,像以前一样创建箱线图,但使用输出参数B

    B = multiple_boxplot(data...);
    

    并添加以下行:

    % compute the mean by group:
    M = cellfun(@mean,data);
    % convert it to pairs of Y values:
    M = mat2cell(repmat(M(:),1,2),ones(size(M,1),1),2);
    % change the medians to means:
    set(B(6,:),{'YData'},M)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-22
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 2018-05-12
      • 2012-08-21
      相关资源
      最近更新 更多