필터 지우기
필터 지우기

barwitherr() Position of errorbars

조회 수: 5 (최근 30일)
Gero Knittel
Gero Knittel 2016년 7월 7일
답변: Martina Callaghan 2018년 6월 3일
Hi everybody,
This is what I want to do (higher quality image as attachment):
A grouped barplot with errorbars. There are two "groups of groups" which should have different colors. Since I did not find a way to change the colors of individual bars but only groups of bars, I put two separate plots with different x values into one figure using "hold on". However, as you can see from the graph, the second plot has a problem with the location of the errorbars. If I remove the "hold on" before the second plot and generate a new figure, the problem disappears, without changing anything else in the code.
figure()
barwitherr(errors(1:a,:),[1:a],data(1:a,:),'BarWidth',0.8);
colormap('summer');
hold on
second = barwitherr(errors(a+1:end,:),[a+1:size(errors,2)],data(a+1:end,:),'BarWidth',0.8);
set(gca,'XTick',[1:length(lines)],'XTickLabel',lines(order));
set(second(1),'facecolor',Colors2(1,:));
set(second(2),'facecolor',Colors2(3,:));
set(second(3),'facecolor',Colors2(5,:));
set(second(4),'facecolor',Colors2(7,:));
It would be truly great if you could help me out here.
With best regards, Gero
  댓글 수: 4
dpb
dpb 2016년 7월 8일
I'd suspect a handle isn't being retrieved correctly when there's two objects on a single axis--that the error bars are at the precise midpoint of the bar groups indicates that likely the function works to place them by retrieving the patch x-positions and adjusts the x-values given by those factors to place them in the middle of the individual bars. That they're all at the midpoint implies that adjustment is coming out as zero for the second case.
I posted a solution to adding error to bar graph here not terribly long ago in which I did figure out a way to get that position; I'll see if I can find that posting and provide a link.
Meanwhile, I'd use the debugger and step through the function and see what seems to go wrong in this case...it may not be too hard to fix up when you see what is actually done.
I note there's some comments on the FEx submission about HG2 causing some issues; what Matlab release are you using; that might have a bearing. I'm still at r2012b so can't check out anything regarding that...
dpb
dpb 2016년 7월 8일
편집: dpb 2016년 7월 8일
<error-bars-added-to-column-plot> is link to my previous submission; you're welcome to see if it'll handle the second case on two axes; I've no idea at the moment how confused it might get. For certain you'll have to retain identifiable handles to the bar plots for the "handle diving" done to retrieve the coordinates. Also, whether this works at all for HG2 is unknown and I've no way to test.

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

답변 (1개)

Martina Callaghan
Martina Callaghan 2018년 6월 3일
The graphics need to be updated immediately, e.g. via drawnow or putting in a pause. In this case the figure gets updated properly and the errorbars are put in the right place. I've updated the file in File Exchange.

카테고리

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