hide one tail of errorbar

47 visualizaciones (últimos 30 días)
Cathie Kessler
Cathie Kessler el 11 de Dic. de 2012
I am generating figures for someone that wants to show only one half of an errorbar on a barplot. In one case, this was easy, as the barplot covered the tail, but in a second case, the offending tail goes beyond the axis so hangs out "below" the barplot.
This is just a one-off, so I don't need to do it programmatically, but I can, if necessary. Any advice?
I already tried inserting a white, rimless rectangle, but I couldn't figure out how to put it "behind" some other plot objects. That would also be an acceptable workaround.
Thanks!

Respuesta aceptada

Kye Taylor
Kye Taylor el 11 de Dic. de 2012
Have you tried something like
x = linspace(0,1);
y = x.^2;
err = randn(size(x));
errorbar(x,y,zeros(size(x)),err)

Más respuestas (3)

Luke Wilhelm
Luke Wilhelm el 11 de Dic. de 2012
Editada: Luke Wilhelm el 11 de Dic. de 2012
Here is an example code that I believe produces what you are looking for (in this case, I have 20 bars in the bar graph):
x=1:20;
y=rand(1,20)
L=zeros(1,20)
U=rand(1,20)
bar(y)
hold on
h=errorbar(x,y,L,U,'k');
set(h,'linestyle','none');
Where U are the upper bounds on your error bars.
I hope this helps,
Luke

Cathie Kessler
Cathie Kessler el 11 de Dic. de 2012
Yes, of course, you're both right. I just didn't know that I could specify L and U values.
Thanks!

Jonathan Epperl
Jonathan Epperl el 11 de Dic. de 2012
Here is a hack that should do what you want it to, odd request though to show only the upper half of the errors... Anyway:
x=1:20;
y=rand(1,20)
L=-rand(1,20)
U=rand(1,20)
bar(y)
hold on
h=errorbar(x,y,L,U,'k');
c = get(h,'Children')
yd = get(c(2),'Ydata');
yd([7:9:end 8:9:end])=nan;
yd(2:9:end)=y;
set(c(2),'YData',yd)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by