barwitherr() Position of errorbars
5 次查看(过去 30 天)
显示 更早的评论
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
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
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!