Matlab 箱线图 : Use a specific percentile as the upper whisker OR remove redundant outliers after manual upper whisker edit

标签 matlab plot boxplot

对于 MATLAB 中的箱线图,我想问一下是否可以使用特定的百分位数作为上须线。我想使用第 95 个百分位作为上部晶须,第 5 个百分位作为下部晶须。

MATLAB 的默认行为是使晶须长度 = 1.5 * IQR(第 75 个百分位数 - 第 25 个百分位数)并且此晶须长度可以更改为 IQR 的另一个倍数,但不能更改为特定的百分位数。请解释一下更改此方法的方法。

例如,对于以下100条数据:

50(重复80次), 76(重复10次), 91, 92, 93, 94, 95, 96, 97, 98, 99, 100

或在 MATLAB 中:

A([1:80],1) = 50; A([81:90],1) = 76; A([91:100],1) = [91:100]; boxplot(A)

有没有办法指定 95 甚至 76 在 mustache 内?还是上 mustache 的值(value)?

我已经使用以下代码调整了上部和下部晶须(尽管本例中不需要下部晶须);然而,此代码不会删除 mustache 内的异常值,从而使结果看起来不清楚。

p([1:2],1) =prctile(A,[5,95])
h = flipud(findobj(gca,'Tag','Upper Whisker'));
for j=1:length(h);
ydata = get(h(j),'YData');
ydata(2) = p(2,j);
set(h(j),'YData',ydata);
end
% Replace all y values of adjacent value
h = flipud(findobj(gca,'Tag','Upper Adjacent Value'));
for j=1:length(h);
ydata = get(h(j),'YData');
ydata(:) = p(2,j);
set(h(j),'YData',ydata);
end
% Replace lower end y value of whisker
h = flipud(findobj(gca,'Tag','Lower Whisker'));
for j=1:length(h);
ydata = get(h(j),'YData');
ydata(1) = p(1,j);
set(h(j),'YData',ydata);
end
% Replace all y values of adjacent value
h = flipud(findobj(gca,'Tag','Lower Adjacent Value'));
for j=1:length(h);
ydata = get(h(j),'YData');
ydata(:) = p(1,j);
set(h(j),'YData',ydata);
end

任何帮助将不胜感激!

谢谢!

最佳答案

您需要添加以下内容:

h = flipud(findobj(gca,'Tag','Outliers'));
for j=1:length(h);
  ydata = get(h(j),'YData');
  xdata = get(h(j),'XData');
  remdata = (ydata >= p(1,j)) & (ydata <= p(2,j));
  ydata(remdata) = [];
  xdata(remdata) = [];
  set(h(j),'XData',xdata,'YData',ydata);
end

关于Matlab 箱线图 : Use a specific percentile as the upper whisker OR remove redundant outliers after manual upper whisker edit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27962191/

相关文章:

file - Matlab 保存扩展名为 m~ 的文件的副本。它们有什么作用?我可以关闭它们吗?

python - 使用 Python 绘制一个圆圈并为其中的区域着色?

python - Pandas 0.19 : Attribute error "unknown property color_cycle" still exists while performing boxplot

r - 如何从 R 中的箱线图中提取 y 轴标签?

python - 使用 seaborn/matplotlib boxplot 时的刻度频率

image - 在 MATLAB 中绘制图像背景

python - 将.mat文件加载到Python后如何获取字符串

matlab - 找到合适的陷波滤波器以从图像中去除图案

r - 在 R 中绘制 data.frame

python - 具有可变线宽的 Matplotlib 图