How do I plot error in both the x and y directions as a shaded area?

8 Ansichten (letzte 30 Tage)
I am trying to plot a Lift:Drag polar (a common graph in aerodynamics for evaluating wings) which has error in both the x and y directions. I am able to plot the points and the error associated with those points using the 'errorbar' function in Matlab, but I was hoping to shade the area between the errorbars. Currently, my plot looks like this:
Is there a way to shade the area between the four bounds for each point? The typical methods using flipud end up filling the center of the u-shape, which I don't want to do. Currently, my code for the 'errorbar' plot looks like this:
figure()
errorbar(ChFl_means, CvFl_means, -CvFl_sem, CvFl_sem, -ChFl_sem, ChFl_sem, 'Color', 'b','LineWidth', 1); %plot Flexed Data
hold on
errorbar(ChE_means, CvE_means, -CvE_sem, CvE_sem, -ChE_sem, ChE_sem, 'Color', 'r','LineWidth', 1); %plot Extended Data
legend('Flexed Posture', 'Extended Posture')
ylabel('Cv')
xlabel('Ch')
  1 Kommentar
Star Strider
Star Strider am 3 Sep. 2019
Anthony Lapsansky added —
I have made a simple version of my data for testing.
figure() %no x error
x = [5 4 3 2 1 0.5 1 2 3 4 5];
y = [0 0.25 0.75 1.5 2 2.5 3 3.5 4.5 4.75 5];
x_err = [0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5];
y_err = [0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5];
hold on
patch([x fliplr(x)], [y+y_err fliplr(y-y_err)],[0.8 0.8 0.8])
errorbar(x,y,-y_err,y_err,-x_err,x_err,'-')
figure() %x error included
x = [5 4 3 2 1 0.5 1 2 3 4 5];
y = [0 0.25 0.75 1.5 2 2.5 3 3.5 4.5 4.75 5];
x_err = [0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5];
y_err = [0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5];
hold on
patch([x+x_err fliplr(x-x_err)], [y+y_err fliplr(y-y_err)],[0.8 0.8 0.8])
errorbar(x,y,-y_err,y_err,-x_err,x_err,'-')

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Subhadeep Koley
Subhadeep Koley am 5 Sep. 2019
Since you want to shade the area between the four bounds for each point, the following code might help you.
% Demo data
x = [5 4 3 2 1 0.5 1 2 3 4 5];
y = [0 0.25 0.75 1.5 2 2.5 3 3.5 4.5 4.75 5];
x_err = [0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25];
y_err = [0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25];
hold on;
% Plotting errorbar
errorbar(x,y,-y_err,y_err,-x_err,x_err,'-','LineWidth', 2);
% Plotting shaded area
for i=1:numel(x)
x_i=[x(i),x(i)+x_err(i),x(i),x(i)-x_err(i)];
y_i=[y(i)+y_err(i),y(i),y(i)-y_err(i),y(i)];
patch(x_i,y_i,'green','FaceAlpha',.2);
end
hold off;
SK_errorbar.png

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