matlab 绘制误差阴影图
1.https://www.ilovematlab.cn/thread-165903-1-1.html 使用面积函数
% 画出误差阴影。
clear;clc;close all;
dat = [0.4945,0.5427,0.5598,0.5333,0.5474,0.4697,0.5231,0.4390;
0.5667,0.6384,0.5139,0.5000,0.5138,0.6087,0.5800,0.5824;
0.5546,0.6148,0.5548,0.5312,0.5493,0.5877,0.5000,0.5800;
0.6158,0.6386,0.6025,0.4988,0.6000,0.6706,0.6300,0.4824;
0.6875,0.5299,0.6000,0.5865,0.6500,0.7121,0.5607,0.5354;
0.5979,0.7516,0.6111,0.6041,0.6589,0.7297,0.7059,0.7151;
0.6875,0.7371,0.7409,0.7571,0.6176,0.6406,0.6800,0.6987;
0.6667,0.8229,0.6958,0.6420,0.7119,0.6557,0.6652,0.7561;
0.6891,0.7083,0.8915,0.7047,0.8207,0.6953,0.6652,0.6667;
0.8667,0.8438,0.8489,0.7977,0.7460,0.8814,0.7727,0.8815;
0.9231,0.8100,0.9263,0.9698,0.9370,0.9500,0.8670,0.9000];
fh=figure(1);clf;
y = (mean(dat'))';
e = (std(dat'))';
x = (1:length(y))';
h = area(x,[y - e, 2 * e]);hold on;
set(h(1),'Visible','off');
set(h(2),'EdgeColor','white','FaceColor',[0.7,0.7,1]);
plot(x,y,'-b','LineWidth',2);
xlabel('Time(day)');
set(gca,'YTick',[0,0.25,0.50,0.75,1.00]);
ylim([0,1]);
ylabel('Succuss Rate (%)');
求出每一行的均值和标准差,用曲线图画出均值,用面积图画出标准差阴影。
2. 使用shadedErrorBar
https://blog.csdn.net/zzx2016zzx/article/details/84000948
shadedErrorBar是一个MATLAB函数,它在一条线而不是离散条上创建一个连续的阴影误差区域。可以显式指定错误区域,也可以根据函数句柄动态计算错误区域。可以通过输入参数和/或返回的绘图对象的句柄来修改绘图的外观。
1、首先准备下载shadedErrorBar.m函数代码,mathworks官网下载或者github
在此我给出已经下载的代码
function varargout=shadedErrorBar(x,y,errBar,varargin)
% generate continuous error bar area around a line plot
% function H=shadedErrorBar(x,y,errBar, ...)
% Purpose
% Makes a 2-d line plot with a pretty shaded error bar made
% using patch. Error bar color is chosen automatically.
% Inputs (required)
% x - vector of x values [optional, can be left empty]
% y - vector of y values or a matrix of n observations by m cases
% where m has length(x);
% errBar - if a vector we draw symmetric errorbars. If it has a size
% of [2,length(x)] then we draw asymmetric error bars with
% row 1 being the upper bar and row 2 being the lower bar
% (with respect to y -- see demo). ** alternatively **
% errBar can be a cellArray of two function handles. The
% first defines statistic the line should be and the second
% defines the error bar.
% Inputs (optional, param/value pairs)
% 'lineProps' - ['-k' by default] defines the properties of
% the data line. e.g.:
% 'or-', or {'-or','markerfacecolor',[1,0.2,0.2]}
% 'transparent' - [true by default] if true, the shaded error
% bar is made transparent. However, for a transparent
% vector image you will need to save as PDF, not EPS,
% and set the figure renderer to "painters". An EPS
% will only be transparent if you set the renderer
% to OpenGL, however this makes a raster image.
% 'patchSaturation'- [0.2 by default] The saturation of the patch color.
% Outputs
% H - a structure of handles to the generated plot objects.
% Examples:
% y=randn(30,80);
% x=1:size(y,2);
% 1)
% shadedErrorBar(x,mean(y,1),std(y),'lineprops','g');
% 2)
% shadedErrorBar(x,y,{@median,@std},'lineprops',{'r-o','markerfacecolor','r'});
%
% 3)
% shadedErrorBar([],y,{@median,@(x) std(x)*1.96},'lineprops',{'r-o','markerfacecolor','k'});
% 4)
% Overlay two transparent lines:
% clf
% y=randn(30,80)*10;
% x=(1:size(y,2))-40;
% shadedErrorBar(x,y,{@mean,@std},'lineprops','-r','transparent',1);
% hold on
% y=ones(30,1)*x; y=y+0.06*y.^2+randn(size(y))*10;
% shadedErrorBar(x,y,{@mean,@std},'lineprops','-b','transparent',1);
% hold off
%
%
% Rob Campbell - November 2009
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parse input arguments
narginchk(3,inf)
params = inputParser;
params.CaseSensitive = false;
params.addParameter('lineProps', '-k', @(x) ischar(x) | iscell(x));
params.addParameter('transparent', true, @(x) islogical(x) || x==0 || x==1);
params.addParameter('patchSaturation', 0.2, @(x) isnumeric(x) && x>=0 && x<=1);
params.parse(varargin{:});
%Extract values from the inputParser
lineProps = params.Results.lineProps;
transparent = params.Results.transparent;
patchSaturation = params.Results.patchSaturation;
if ~iscell(lineProps), lineProps={lineProps}; end
%Process y using function handles if needed to make the error bar dynamically
if iscell(errBar)
fun1=errBar{1};
fun2=errBar{2};
errBar=fun2(y);
y=fun1(y);
else
y=y(:).';
end
if isempty(x)
x=1:length(y);
else
x=x(:).';
end
%Make upper and lower error bars if only one was specified
if length(errBar)==length(errBar(:))
errBar=repmat(errBar(:)',2,1);
else
s=size(errBar);
f=find(s==2);
if isempty(f), error('errBar has the wrong size'), end
if f==2, errBar=errBar'; end
end
if length(x) ~= length(errBar)
error('length(x) must equal length(errBar)')
end
%Log the hold status so we don't change
initialHoldStatus=ishold;
if ~initialHoldStatus, hold on, end
H = makePlot(x,y,errBar,lineProps,transparent,patchSaturation);
if ~initialHoldStatus, hold off, end
if nargout==1
varargout{1}=H;
end
function H = makePlot(x,y,errBar,lineProps,transparent,patchSaturation)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot to get the parameters of the line
H.mainLine=plot(x,y,lineProps{:});
% Work out the color of the shaded region and associated lines.
% Here we have the option of choosing alpha or a de-saturated
% solid colour for the patch surface.
mainLineColor=get(H.mainLine,'color');
edgeColor=mainLineColor+(1-mainLineColor)*0.55;
if transparent
faceAlpha=patchSaturation;
patchColor=mainLineColor;
else
faceAlpha=1;
patchColor=mainLineColor+(1-mainLineColor)*(1-patchSaturation);
end
%Calculate the error bars
uE=y+errBar(1,:);
lE=y-errBar(2,:);
%Add the patch error bar
%Make the patch
yP=[lE,fliplr(uE)];
xP=[x,fliplr(x)];
%remove nans otherwise patch won't work
xP(isnan(yP))=[];
yP(isnan(yP))=[];
if(isdatetime(x))
H.patch=patch(datenum(xP),yP,1);
else
H.patch=patch(xP,yP,1);
end
set(H.patch,'facecolor',patchColor, ...
'edgecolor','none', ...
'facealpha',faceAlpha)
%Make pretty edges around the patch.
H.edge(1)=plot(x,lE,'-','color',edgeColor);
H.edge(2)=plot(x,uE,'-','color',edgeColor);
uistack(H.mainLine,'top') % Bring the main line to the top
2、选择shadedErrorBar.m文件黏贴到matalb的toolbox文件下面,我设置的路径是D:\Program Files\MATLAB\R2016b\toolbox\shadedErrorBaryy。然后选择matlab主页的设置路径
3、将预先设置的文件添加进去
4、检查是否设置成功
在matlab运行窗口输入help shadedErrorBar,如果出现以下情况说明 shadedErrorBar函数设置成功
5、最后运行
% Prepare data
y=randn(30,80)*5;
x=(1:size(y,2))-40;
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP)+60;
% Make the plot
clf
shadedErrorBar(x,y,{@mean,@std});
% Overlay the raw data
hold on
plot(x,y,'.','color',[0.5,0.5,0.95])
grid on
% Prepare data for first line
y=ones(30,1)*x;
y=y+0.06*y.^2+randn(size(y))*10;
clf
shadedErrorBar(x,y,{@mean,@std},'lineprops','-b','patchSaturation',0.33)
% Overlay second line
hold on
shadedErrorBar(x,2*y+20,{@mean,@std},'lineprops',{'-go','MarkerFaceColor','g'});
%Overlay third line
y=randn(30,80)*5;
x=(1:size(y,2))-40;
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP)+60;
% Make this line non-transparent
shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r','transparent',false,'patchSaturation',0.075)
grid on
% Prepare data
y=randn(30,80)*5;
x=(1:size(y,2));
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP);
% Plot
clf
s = shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r');
% Set face and edge properties
set(s.edge,'LineWidth',2,'LineStyle',':')
s.mainLine.LineWidth = 5;
s.patch.FaceColor = [0.5,0.25,0.25];
% Overlay data points post-hoc
hold on
plot(s.mainLine.XData, s.mainLine.YData,'or','MarkerFaceColor','w')
grid on
set(gca,'XTickLabel',[],'YTickLabel',[])
% Post-hoc modifications of line properties
y=randn(256,80)*5;
x=(1:size(y,2));
yP = cos( linspace(-2*pi,2*pi,length(x)) )*10;
y = bsxfun(@plus,y,yP);
shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r')
hold on
y=mean(y)+16;
errbar = [2*ones(1,length(x)) ; 4*ones(1,length(x))];
shadedErrorBar(x, y, errbar, 'lineprops', '-g')
————————————————
版权声明:本文为CSDN博主「猪猪侠喜欢躲猫猫」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zzx2016zzx/article/details/84000948
matlab 绘制误差阴影图相关推荐
- Matlab绘制带误差线的柱状图
Matlab可绘制带误差线的柱状图(需下载barweb (BARgraph With Error Bars) - File Exchange - MATLAB Central并设置路径),成图如下所示 ...
- Python如何绘制误差直方图?曲线的阴影图?shade range graph
问题抽象:Python如何绘制曲线的阴影图? =============================== 建议的方案: flights = sns.load_dataset("fligh ...
- Matlab 三维相图,用MATLAB绘制Pb-Sn-Sb三维立体相图
第41卷 第8期 稀 有 金 CHINESE J0URNAL OF RARE METALS 2017年 8月 Aug.2017 用 MATLAB绘制 Pb-Sn-Sb三维立体 相 图 周 亮 ,孔令鑫 ...
- nyquist图怎么画matlab,用MATLAB绘制Nyquist图
<用MATLAB绘制Nyquist图>由会员分享,可在线阅读,更多相关<用MATLAB绘制Nyquist图(9页珍藏版)>请在人人文库网上搜索. 1.用MATLAB绘制Nyqu ...
- matlab绘制圆,且求解两个圆的交点坐标
前言 这里简单记录下对于matlab绘制圆,以及求解两圆交点的坐标的实现(包括C++). 一 绘制圆 circle.m文件: function [] = circle(x, y, r, color) ...
- matlab系统的根轨迹,实验五 利用MATLAB绘制系统根轨迹
<实验五 利用MATLAB绘制系统根轨迹>由会员分享,可在线阅读,更多相关<实验五 利用MATLAB绘制系统根轨迹(6页珍藏版)>请在人人文库网上搜索. 1.实验五 利用MAT ...
- Matlab 绘制三维立体图(以地质异常体为例)
Matlab 绘制三维立体图(以地质异常体为例) 参考文章: (1)Matlab 绘制三维立体图(以地质异常体为例) (2)https://www.cnblogs.com/yangwenbo214/p ...
- matlab绘制频散曲线,Matlab绘制频散曲线程序代码.docx
Matlab绘制频散曲线程序代码.docx 下载提示(请认真阅读)1.请仔细阅读文档,确保文档完整性,对于不预览.不比对内容而直接下载带来的问题本站不予受理. 2.下载的文档,不会出现我们的网址水印. ...
- matlab绘制X,Y二维散点图并标出序号
matlab绘制X,Y二维散点图并标出序号 标签: matlab 2016-11-22 12:20 193人阅读 评论(0) 收藏 举报 分类: matlab(1) 版权声明:本文为博主原创文章, ...
最新文章
- LeetCode 54. Spiral Matrix--Python解法--螺旋排序
- 连载-第1章绪论 1.2嵌入式处理器
- Python Tornado搭建高并发Restful API接口服务
- (私人收藏)2019科协WER解决方案
- OpenCV Python教程(3)(4)(5): 直方图的计算与显示 形态学处理 初级滤波内
- MyBatis 架构分层与模块划分
- python爬虫知乎图片_Python爬虫入门教程 25-100 知乎文章图片爬取器之一
- java泛型_Java核心知识 基础五 JAVA 泛型
- java猜拳_java猜拳
- SparkStreaming之mapWithState
- linux终奌站 信息 格式 更改 /etc/bashrc
- Ceph源码解析:PG peering
- Logstash自定义grok正则匹配规则
- windows下发文件到linux中文名乱码解决办法
- 软件测试系统性总结思维导图
- FlashFXP,flashfxp建立ftp站点
- 计算机应用基础——计算机硬件(三)
- 用c语言编写一个日期计算器
- 2022UI自动化测试框架搭建 —— yaml文件管理定位元素
- CMD命令汇总 电脑入门知识【装机吧】
热门文章
- MCU, SOC 区别
- peakcoo分享:soc芯片
- 解决 You could try using --skip-broken to work around the problem,rpm -Va --nofiles --nodigest问题
- 火出圈的3D人脸识别如何让“刷脸”更安全?
- Android 如何判断手机处于电源充电状态还是USB连接状态?
- 支付宝小程序Serverless服务架构演进 | mPaaS 线下沙龙 CodeDay#1 分享实录
- LiveVideoStackCon 2018 打造多媒体人自己的盛宴
- 用计算机模拟动物实验的弊端,无需动物实验也能预测纳米颗粒毒性,计算机模拟助力材料研发...
- 2019第二届北京国际无人值守零售展览会【官宣】
- 老版举证平台DB向2023年新版国家标准DB的转换