【问题标题】:How to change the colors of the outliers in matlab boxplot? [closed]如何更改matlab boxplot中异常值的颜色? [关闭]
【发布时间】:2020-11-30 01:02:07
【问题描述】:

我正在处理 matlab boxplot,我想更改异常值的颜色。我厌倦了这样的事情而没有成功:

figure
hold on
A=boxplot(Data,Gr,'labels',Labels,'colors',RGB,'notch','on');


grid on
ylabel('Length','Interpreter','latex','FontSize',25)
ax=gca;
ax.XTick = [1 : 44]; 
ax.XTickLabels=Labels
ax.XTickLabelRotation = angle;
ax.TickLabelInterpreter= 'Latex';

h = findobj(gcf,'tag','Outlier')

for i = 1:numel(h)
if rem(i,2)==0
    h(i).MarkerEdgeColor = green;

end
end

因此我很喜欢 findobj 函数。数据是一组不同的向量,每个向量包含几个数字。 Gr 对其中的每一个进行分组,而 Label 包含多个名称。 RGB 是一个 22x3 数组(每个变量一种颜色)。它总是让我返回红色异常值。谁能帮帮我?

【问题讨论】:

  • 请发布一些我们可以按原样运行的(短)代码;也就是说,定义所有变量。并解释为什么它不能做你想做的事情
  • 如果我知道它为什么不符合我的要求,我就不会问了。无论如何,箱线图的部分很好,但我无法成功改变异常值的颜色。
  • “为什么”是指症状,而不是原因

标签: matlab statistics data-science boxplot


【解决方案1】:

我终于设法解决了我的问题。标签错误:我将 'Outlier' 更改为 'Outliers' 并且代码运行。还是谢谢你

#编辑 01/10/2020

我想与社区分享我最近发现的一些有用的经验,以便添加一些可以帮助 Matlab 用户的提示:

基本上我想为箱线图及其异常值着色。

结果在图片中报告

angle=315;

Random = randn(5,5);

Data = [Random(1,1:end) Random(2,1:end) Random(3,1:end) Random(4,1:end) 
Random(5,1:end)];

Gr = [zeros(size(Random(1,1:end))) ones(size(Random(1,1:end)))... 
2*ones(size(Random(1,1:end))) 3*ones(size(Random(1,1:end)))... 
4*ones(size(Random(1,1:end)))];

RGB = [rgb('DeepskyBlue') ; rgb('MediumSpringGreen') ; rgb('DeepSkyBlue'); 
rgb('MediumSpringGreen'); rgb('DeepSkyBlue')];

Labels = 
 {'$Label_{1}$','$Label_{2}$','$Label_{3}$','$Label_{4}$','$Label_{5}$'}


figure
hold on
B=boxplot(Data,Gr,'labels',Labels,'colors',RGB,'notch','on');

ylabel('$Your Data$','Interpreter','latex','FontSize',25)
bx = gca;
bx.XTick = [1 : 5]; 
bx.XTickLabels=Labels;
bx.XTickLabelRotation = angle;
bx.TickLabelInterpreter= 'Latex';

 n = findobj(gcf,'tag','Outliers')

 for j = 1:numel(n)
   if rem(n(j).XData(1),2)~=0
       n(j).MarkerEdgeColor = rgb('DeepSkyBlue');
        else
    n(j).MarkerEdgeColor = rgb('MediumSpringGreen');
 end

结束

rgb 函数可以在 mathworks 中找到。基本上,这个想法是用与箱线图相同的颜色来查找和重新着色箱线图的奇数和偶数定位的异常值。我希望您发现它对您的目的有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 2017-10-04
    相关资源
    最近更新 更多