当前位置:网站首页>Matlab 绘制阴影误差图
Matlab 绘制阴影误差图
2022-07-26 08:53:00 【jeff one】
Matlab 绘制阴影误差图
代码如下:
clear,clc;
x = 0:10:500;
y_true = 30*sind(x) + x/10;
sigma = 3;
y_measured = y_true + sigma*randn(size(x));
plot(x,y_true,'k','linewidth',2)
hold on
plot(x,y_measured,'color',[0.0118 0.2078 0])
ylabel( 'Y轴');xlabel('X轴');
% 绘制不确定性阴影区间
errorshade(x,y_measured,sigma,[0 1 0.7])
legend('真实值','测量值 \pm\sigma = 3 mV ','location','northwest')
legend box off
axis tight
title('好看的阴影误差图')
grid minor
errorshade 函数:
function h = errorshade(x,y,sigma,color,varargin)
%errorshade绘制阴影区域以指示高斯不确定性。
%通过生成指定颜色的RGB图像并设置透明度来作图
%% 语法规则
% errorshade(x,y,sigma,color)
% errorshade(...,'resolution',res)
% errorshade(...,'average',N)
% h = errorshade(...)
%
%% 简介
%
% %errorshade(x,y,sigma ,color)以高斯阴影区域为中心绘制
% x,y:为数据行。
%sigma:表示阴影的一个标准偏差
% color:为rgb值的三元素向量。
%% 举例
%数据
% x = 0:10:500;
% y_true = 30*sind(x) + x/10;
% sigma = 3;
% y_measured = y_true + sigma*randn(size(x));
% plot(x,y_true,'k','linewidth',2)
% hold on
% plot(x,y_measured,'color',[0.0118 0.2078 0])
% ylabel 'some values in mV'
%
% % 绘制不确定性阴影区间
% errorshade(x,y_measured,sigma,[0.0824 0.6902 0.1020])
% legend('true value','measured value \pm\sigma = 3 mV uncertainty','location','northwest')
% legend boxoff
% axis tight
%% Error checks:
narginchk(4,inf)
assert(numel(color)==3,'输入错误: 颜色必须是三元素向量.')
assert(numel(x)==numel(y),'输入错误::x 和 y 维度必须相等')
assert(isscalar(sigma)==1,'输入错误: sigma必须是标量.')
%% Input parsing
tmp = strncmpi(varargin,'resolution',3);
if any(tmp)
res = varargin{
find(tmp)+1};
if isscalar(res)
res = [res res];
else
assert(numel(res)==2,'输入错误: 分辨率必须是标量或二元素向量.')
end
else
res = 2500*[1 1];
end
tmp = strncmpi(varargin,'average',2);
if any(tmp)
avg = varargin{
find(tmp)+1};
assert(isscalar(avg)==1,'输入错误: 移动平均距离必须为标量.')
y = imfilter(y(:),fspecial('average',[avg 1]),'replicate');
end
buffer = 3*sigma; % This is the padding to add around all measurements in the vertical dimension.
%% 限制范围:
% 制作一个与数据缓冲区的尺寸相对应的网格:
[X,Y] = meshgrid(linspace(min(x),max(x),res(1)),linspace(min(y)-buffer,max(y)+buffer,res(2)));
% Find y locations along all x points of the grid
yi = interp1(x,y,linspace(min(x),max(x),res(1)));
% 正态分布:
P = (1/sqrt(2*pi*sigma^2)) * exp(-(bsxfun(@minus,Y,yi)).^2/(2*sigma^2));
%每个点到yi的距离将用作透明度的量度:
Z = P-min(P(:));
Z = Z/max(Z(:));
%创建指定颜色的RGB图像:
RGB = cat(3,color(1)*ones(size(Z)),color(2)*ones(size(Z)),color(3)*ones(size(Z)));
% 绘制颜色的RGB图像:
h = image(RGB,'xdata',X(1,:),'ydata',Y(:,1));
axis xy
% 设置透明度:
set(h,'alphadata',Z)
% 将渲染器设置为OpenGL,因为透明度仅适用于OpenGL:
set(gcf,'renderer','OpenGL');
% 底部:
uistack(h,'bottom')
%% 清除:
if nargout==0
clear h
end
end
边栏推荐
- Arbitrum launched the anytrust chain to meet the diverse needs of ecological projects
- Super potential public chain dfinity -- the best time for DFI developers to enter
- node-v下载与应用、ES6模块导入与导出
- NFT与数字藏品到底有何区别?
- 深度学习常用激活函数总结
- TypeScript版Snowflake主键生成器
- Espressif plays with the compilation environment
- What are the contents of Oracle OCP and MySQL OCP certification exams?
- 2000年的教训。web3是否=第三次工业革命?
- codeforces dp合集
猜你喜欢
Transfer guide printing system based on C language design
Cadence(十)走线技巧与注意事项
pl/sql之动态sql与异常
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
ES6模块化导入导出)(实现页面嵌套)
Database operation topic 1
Media at home and abroad publicize that we should strictly grasp the content
After MySQL 8 OCP (1z0-908), hand in your homework
node-v下载与应用、ES6模块导入与导出
PXE principles and concepts
随机推荐
Human computer interaction software based on C language
codeforces dp合集
【LeetCode数据库1050】合作过至少三次的演员和导演(简单题)
Espressif 玩转 编译环境
Kotlin properties and fields
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
Pop up window in Win 11 opens with a new tab ---firefox
高数 | 武爷『经典系列』每日一题思路及易错点总结
unity简易消息机制
Cve-2021-26295 Apache OFBiz deserialization Remote Code Execution Vulnerability recurrence
Cve-2021-21975 VMware SSRF vulnerability recurrence
Day06 homework - skill question 6
SSH,NFS,FTP
PXE principles and concepts
2000年的教训。web3是否=第三次工业革命?
Study notes of automatic control principle -- dynamic model of feedback control system
idea快捷键 alt实现整列操作
What are the contents of Oracle OCP and MySQL OCP certification exams?
Study notes of automatic control principle -- correction and synthesis of automatic control system
Cadence (x) wiring skills and precautions