Borrar filtros
Borrar filtros

How to plot using errorbar but the error bar only in every 5 points

49 visualizaciones (últimos 30 días)
Mad Gano
Mad Gano el 18 de En. de 2023
Respondida: dpb el 18 de En. de 2023
I want to plot a matrix (x,y,erro) which has 1000 rows.
Case_1: When I use errorbar it is very hard to see the original line
Case_2: If I plot every 20 steps I lose some infos
Case_3: If I plot the matrix twice ('errorbar' and 'plot') the two lines of the plots differ.
See the image.
I use actually a legend, so it is important for me to have the errorbar as a line (I mean '-')
How can plot the whole matrix with only a few errorbars?

Respuestas (1)

dpb
dpb el 18 de En. de 2023
First, 3) above isn't so -- if you plot the same data with plot() and with errorbar() the two lines will overlap identically; the problem in that figure is you're comparing 2) to 1) -- plot() and friends draw straight lines between the plotted points; if there's sufficient curvature between the points as in your examples above, then when overlay with more points, then the difference does show up.
To do what you want wasn't foreseen by TMW with a builtin option so you'll have to do it yourself but it's not difficult...from an example for errorbar()...
x = linspace(0,2,1000);
y = exp(x);
err = zeros(size(y));
N=100;
ixErr=1:N:numel(y);
err(ixErr) = 0.3*y(ixErr);
hEB=errorbar(x,y,err);
Adjust N as wished to pick as many as you wish...oh. Forgotted about 'CapSize' -- it still draws the vertical line caps for all the points even though the error value is zero--bummer.
In that case, it's probably simpler to not draw the line for errorbar but only with the original plot().
figure
hL=plot(x,y,'b-');
hold on
hEB=errorbar(x(ixErr),y(ixErr),err(ixErr),'b');
You may have to create a fake errorbar with no actual data that uses the line style and color you want the legend to be to avoid the previous artifact of different line segments between the actual and errorbar.
Dealing with this more cleanly would seem a worthwhile enhancement request for errorbar.

Categorías

Más información sobre Errorbars 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