barwitherr() Position of errorbars

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 comentarios

dpb
dpb el 7 de Jul. de 2016
Is File Exchange submission; perhaps the author could advise...
But, while your attached figure is so small can't read the axis to see what they are, looks like there's something not right with the x-values you've given for the second set--they're offset to the right as though the values are too large.
Perhaps retrieve the x locations of the bars and the errorbars for that group would lead to understanding of what's gone wrong...
Gero Knittel
Gero Knittel el 8 de Jul. de 2016
Thank you very much for the reply. I attached a higher quality image (to the original post).
The error bars at the second set are all plotted at one exact location. If I open a new figure instead of plotting the second plot into the first figure (without changing the x-values), the error bars are at the correct positions.
And you're right, I will contact the author.
And I will try to find out how to retrieve the x locations of the errorbars.
dpb
dpb el 8 de Jul. de 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 el 8 de Jul. de 2016
Editada: dpb el 8 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Martina Callaghan
Martina Callaghan el 3 de Jun. de 2018

0 votos

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.

Categorías

Preguntada:

el 7 de Jul. de 2016

Respondida:

el 3 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by