我正在处理matlab箱图,我想更改离群值的颜色。我累了像这样的东西,没有成功:
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的阵列(每个变量一种颜色)。它总是使我返回红色异常值。谁能帮我吗?
答案 0 :(得分:1)
我终于设法解决了我的问题。标记错误:我将“异常值”更改为“异常值”,然后代码运行。还是谢谢你
#Edit 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中找到。基本上,这个想法是用箱图的相同颜色查找箱图的奇数和偶数离位值并对其重新着色。希望您觉得对您的目的有用。