Standardising errorbar whiskers

조회 수: 3 (최근 30일)
Stephen McKeever
Stephen McKeever 2011년 8월 24일
Hi
I am using a set of data to construct a plot of errorbars with associated standard errors and whiskers for row=0:5;
for col = 0:2;
x=data(1+row,1+col);
y=data(1+row,4+col);
e=data(1+row,7+col);
if row==0;
shape='sk';
elseif row==1;
shape='dk';
elseif row==2;
shape='^k';
end
subplot (3,1,1)
errorbar(x,y,e,shape, 'MarkerFaceColor','k','MarkerSize', 8, 'LineWidth',1),ylim ([0 1]),xlim ([0 3.5]);
hold on
box('off');
end
end
Unfortunately the whisker ends are not a uniform length. As can be seen in this example. I have added a highlight to emphasise what I am referring to.
Either I would like to stop this increase happening or set the size of the whisker plot ends.
Please help (at the wits end with my whiskers)
Stephen
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 8월 24일
We don't have data and row to run your example and from the code nothing abnormal should happen.

댓글을 달려면 로그인하십시오.

답변 (3개)

Daniel Shub
Daniel Shub 2011년 8월 26일
Is your xscale linear or log?
get(gca, 'xscale')
I have had problems with errorbar widths and log scales. If you are using a log scale, you could use
errorbar(log(x), ...
and a linear scale. The new numbers shouldn't be a problem since you are replacing the tick labels with text anyways.

Stephen McKeever
Stephen McKeever 2011년 8월 29일
Hi
Daniel - I am not using a log scale.
I have removed the loop as suggest by another Matlab user. This worked well to a point. I have added some sample data to my DropBox to accompany the below function. http://db.tt/W6zhEA9
Cheers Stephen
function test_whiskers
load data
%This worked well
subplot (3,1,1)
hold on
h=errorbar(data(1:6,1)',data(1:6,4)',data(1:6,7)','k','MarkerFaceColor','k','MarkerSize',6, 'LineWidth',1,'linestyle','none'); ylim ([0 1]),xlim ([0 3.5]);
set(h(1),'marker','s')
h=errorbar(data(1:6,2)',data(1:6,5)',data(1:6,8)','k','MarkerFaceColor','k','MarkerSize',6, 'LineWidth',1,'linestyle','none'); ylim ([0 1]),xlim ([0 3.5]);
set(h(1),'marker','d')
h=errorbar(data(1:6,3)',data(1:6,6)',data(1:6,9)','k','MarkerFaceColor','k','MarkerSize',6, 'LineWidth',1,'linestyle','none'); ylim ([0 1]),xlim ([0 3.5]);
set(h(1),'marker','^')
text(-0.4,0.9,'a)','FontSize',12)
% For this plot though the whisker ends are quite large and I need the
% makers to be consistent with the groupings in graph a)
subplot (3,1,2)
hold on
h=errorbar(data(4,1:3)',data(4,4:6)',data(4,7:9)','k','MarkerFaceColor','k','MarkerSize',6, 'LineWidth',1,'linestyle','none'); ylim ([0 1]),xlim ([0 3.5]);
set(h(1),'marker','s')
text(-0.4,0.9,'b)','FontSize',12)
%So I tried separating the lines and changing the marker style but the
%whisker ends increase in size again
subplot (3,1,3)
hold on
h=errorbar(data(4,1)',data(4,4)',data(4,7)','k','MarkerFaceColor','k','MarkerSize',6, 'LineWidth',1,'linestyle','none'); ylim ([0 1]),xlim ([0 3.5]);
set(h(1),'marker','s')
h=errorbar(data(4,2)',data(4,5)',data(4,8)','k','MarkerFaceColor','k','MarkerSize',6, 'LineWidth',1,'linestyle','none'); ylim ([0 1]),xlim ([0 3.5]);
set(h(1),'marker','d')
h=errorbar(data(4,3)',data(4,6)',data(4,9)','k','MarkerFaceColor','k','MarkerSize',6, 'LineWidth',1,'linestyle','none'); ylim ([0 1]),xlim ([0 3.5]);
set(h(1),'marker','^')
text(-0.4,0.9,'c)','FontSize',12)
end

Oleg Komarov
Oleg Komarov 2011년 8월 29일
The length of the horizontal line for the whiskers is proportional to [xdata(1) xdata(end)] the range on the x-axis.
In brief, if you have 5 points and their position on the x-axis is 1, 2, 3, 4, 5 the horizontal line will be proportional to 4.
You get different lengths because you plot several groups of points and the range is not assured to be constant.
There are two ways to get the same length for the horizontal line:
  1. Force the range for each group to be constant by adding fake points to each group such that xdata(end) - xdata(1) = k. In order for these fake point to not appear on the graph, simply set some y-values out of the ylim
  2. Modify manually the whiskers
To visualize the whiskers after you finished plotting one graph:
h = findall(gca,'Type','Line');
plot(get(h(2),'Xdata'),get(h(2),'Ydata'))
Good luck

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by