![Screen Shot 2020-02-10 at 12.38.24 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270886/Screen%20Shot%202020-02-10%20at%2012.38.24%20PM.png)
Bar Plots with errorbars with limits
15 次查看(过去 30 天)
显示 更早的评论
I am tring to draw a bar plot where my highest value on y-axis is 1. Then I want to draw errorbars(standard error of the mean) for each bar. But while doing so, for my highest bar, the errorbar is crossing my highest limit 1. How can I limit my errorbars for my plot. Thank you.
2 个评论
the cyclist
2020-2-10
Can you post an example of what you mean? If I run the code
figure
errorbar(0:0.1:1,(0:0.1:1)/10)
ylim([0 1])
then the figure I get is
![Screen Shot 2020-02-10 at 12.38.24 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270886/Screen%20Shot%202020-02-10%20at%2012.38.24%20PM.png)
The error bars are automatically cut off at the top.
采纳的回答
the cyclist
2020-2-10
Do you mean something like this?
% Pretend data
x = linspace(0,10,25);
y = linspace(0,1,25);
se = y/10;
% Amount that error bar will extend above 1
se_extra = (y + se) - 1;
% Amount of error bar to chop off upper bar
se_chop = max(0,se_extra);
% Amount to plot
se_top = se - se_chop;
se_bot = se;
figure
errorbar(x,y,se_bot,se_top)
xlim([0 11])
ylim([0 1])
![Screen Shot 2020-02-10 at 2.29.00 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270901/Screen%20Shot%202020-02-10%20at%202.29.00%20PM.png)
0 个评论
更多回答(1 个)
Marta G
2020-2-10
Hello,
I am not sure if I understand your problem. You might get what you want if you work with the command ylim.
With your figure, you might get the same result if you use ylim([0 1]). You can slightly increase the upper limit and see if that solves your problem. If you want to this on a loop i would suggest adding a variable for this upperlimit.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!