Filter löschen
Filter löschen

barwitherr() Position of errorbars

5 Ansichten (letzte 30 Tage)
Gero Knittel
Gero Knittel am 7 Jul. 2016
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 Kommentare
dpb
dpb am 8 Jul. 2016
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 am 8 Jul. 2016
Bearbeitet: dpb am 8 Jul. 2016
<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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Martina Callaghan
Martina Callaghan am 3 Jun. 2018
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.

Kategorien

Mehr zu Errorbars finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by