How to get different sizes of horizontal and vertical error bars?
29 次查看(过去 30 天)
显示 更早的评论
So I have to put error bars for both horizontal and vertical but I have different x-axis and y-axis scale so my horizontal error bar is too tiny. How do I change the length of the horizontal error bar ? Thank you for advance for helping. Hve a nice day !
err_1 = 0.1*ones(size(Error_c1));
err_2 = 0.1*ones(size(Error_c2));
err_3 = 0.1*ones(size(Error_c3));
err_4 = 0.1*ones(size(Error_c4));
errorbar(aoa,Lift_c1,err_1,"both");
errorbar(aoa,Lift_c2,err_2,"both");
errorbar(aoa,Lift_c3,err_3,"both");
errorbar(aoa,Lift_c4,err_4,"both");
0 个评论
回答(1 个)
Star Strider
2024-1-9
One option would be to use:
axis equal
or:
axis('equal')
There is no obvious way to scale them otherwise.
2 个评论
Star Strider
2024-1-9
编辑:Star Strider
2024-1-9
My pleasure!
The easiest way to determine the plot data aspect ratio is to use the daspect function. You can uyse this information to scale the shorter error bar lengths to be proportional to the longer error bar lengths. (I do not have enough information from your initial post to determine how best to do this in your specific situation.)
Getting that information is relatively straightforward —
xv = linspace(0, 10, 100);
yv = 100*exp(-0.25*xv) .* sin(2*pi*xv/1.5);
errx = rand(size(xv));
erry = rand(size(yv));
figure
errorbar(xv, yv, errx, errx, erry, erry)
grid
xlabel('X')
ylabel('Y')
title('Original')
figure
hp = plot(xv, yv); % Plot Original Data To Get Aspect Ratio Of Plot
m = daspect; % Aspect Ratio
sr = m(2)/m(1); % SCaling Ratio
hold on
errorbar(xv, yv, errx*sr, errx*sr, erry, erry, 'Color',hp.Color) % Plot 'errorbar' With Scaled X-Errors
hold off
grid
xlabel('X')
ylabel('Y')
title('Scaled Error Bars')
Experiment with this with your data to get the result you want. You can apply the ‘scaling ratio’ to either set of error bars.
EDIT — Corrected typographical errors.
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!