当前位置:网站首页>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

边栏推荐
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- pl/sql之集合
- 第6天总结&数据库作业
- Study notes of automatic control principle --- stability analysis of control system
- Web3 Games: current situation and future
- [recommended collection] MySQL 30000 word essence summary index (II) [easy to understand]
- NPM add source and switch source
- Typescript snowflake primary key generator
- Database operation topic 2
- Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
猜你喜欢

Deploy prometheus+grafana monitoring platform

Kotlin properties and fields

Day06 homework -- skill question 2

高数 | 武爷『经典系列』每日一题思路及易错点总结

Study notes of automatic control principle --- stability analysis of control system

【LeetCode数据库1050】合作过至少三次的演员和导演(简单题)

2000年的教训。web3是否=第三次工业革命?

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output

JS file import of node

Study notes of automatic control principle -- correction and synthesis of automatic control system
随机推荐
Web overview and b/s architecture
PAT 甲级 A1076 Forwards on Weibo
P3743 Kotori's equipment
My meeting of OA project (query)
[encryption weekly] has the encryption market recovered? The cold winter still hasn't thawed out. Take stock of the major events that occurred in the encryption market last week
数据库操作 题目一
My meeting of OA project (meeting seating & submission for approval)
Registration of finite element learning knowledge points
数据库操作技能7
QtCreator报错:You need to set an executable in the custom run configuration.
Ansible important components (playbook)
Numpy Foundation
Datawhale panda book has been published!
Typescript encryption tool passwordencoder
网络安全漫山遍野的高大上名词之后的攻防策略本质
P1825 [USACO11OPEN]Corn Maze S
[suggestions collection] summary of MySQL 30000 word essence - locking mechanism and performance tuning (IV) [suggestions collection]
Which of count (*), count (primary key ID), count (field) and count (1) in MySQL is more efficient? "Suggested collection"
Day06 operation -- addition, deletion, modification and query
js闭包:函数和其词法环境的绑定