matlab条形图添加误差线_绘制数据图像并添加误差线

本文介绍了如何在MATLAB中使用errorbarxy函数绘制数据图像,并添加x轴和y轴上的误差线。该函数允许指定误差范围,并可以自定义颜色。示例代码展示了如何创建带误差线的条形图,并提供了将误差线包含进图例显示的方法。
摘要由CSDN通过智能技术生成

Plot data with error bars on both x and y axes

ERRORBARXY is a function to generate errorbars on both x and y axes with specified errors modified from codes written by Nils Sjöberg (http://www.mathworks.com/matlabcentral/fileexchange/5444-xyerrorbar)

errorbarxy(x, y, lx, ux, ly, uy) plots the data with errorbars on both x and y axes with error bars [x-lx, x+ux] and [y-ly, y+uy]. If there is no error on one axis, set corresponding lower and upper bounds to [].

errorbarxy(x, y, errx, erry) plots the data with errorbars on both x and y axes with error bars [x-errx, x+errx] and [y-erry, y+erry]. If there is no error on one axis, set corresponding errors to [].

errorbarxy(..., COLOR) plots data as well as errorbars in specified colors. COLOR is a cell array of 3 element, {cData, cEBx, cEBy}, where cData specifies the color of main plot, cEBx specifies the color of errorbars along x axis and cEBy specifies the color of errorbars along y axis.

errorbarxy(AX,...) plots into AX instead of GCA.

H = errorbar(...) returns a vector of errorbarseries handles in H, within which the first element is the handle to the main data plot and the remaining elements are handles to the rest errorbars.

For example

x = 1:10;

xe = 0.5*ones(size(x));

y = sin(x);

ye = std(y)*ones(size(x));

errorbarxy(x,y,xe,ye,{'k', 'b', 'r'});

draws symmetric error bars on both x and y axes.

NOTE: errorbars are excluded from legend display. If you need to include errorbars in legend display, do the followings:

H=errorbarxy(...);

arrayfun(@(d) set(get(get(d,'Annotation'),'LegendInformation'),...

'IconDisplayStyle','on'), H(2:end)); % include errorbars

hEB=hggroup;

set(H(2:end),'Parent',hEB);

set(get(get(hEB,'Annotation'),'LegendInformation'),...

'IconDisplayStyle','on'); % include errorbars in legend as a group.

legend('Main plot', 'Error bars');

Developed under Matlab version 7.10.0.499 (R2010a)

Created by Qi An

anqi2000@gmail.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值