常用Matlab作图命令
2.3 在原图上继续作图 hold on
[x,y,z] = peaks; pcolor(x,y,z) shading interp hold on contour(x,y,z,20,'k') hold off
2.4 同一图中作多个图
1 0.8 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.2 -0.8 -1 -0.4 0.2 0.6 1
subplot(1, 2, 1); % 定义第一个子图区域。 subplot(1, 2, 2); % 定义第二个子图区域。
Default 10 8 6 4 2 10 8 6 4 2
X scale manipulated
0
2
4
6
8
1
3
7
Y scale manipulated 9 9
Both scales manipulated
data=normrnd (0,1,30,2);
0.3
p=capaplot(data,[-2,2]) p= 0.9199
0.25
0.2
0.15
0.1
0.05
0 -4
-3
-2
-1
0
1
2
3
4
1.10 附加有正态密度曲线的直方图
25
r = normrnd (10,1,100,1);
20
histfit(r)
0.3
0.25
Density
0.2
0.15
0.1
0.05
0
7
8
9
10
11 12 Critical Value
13
14
15
16
normspec([10 Inf],11.5,1.25)
1.12 二项分布的函数图
0.35
p = 0.2; % Probability of success for each trial n = 10; % Number of trials k = 0:n; % Outcomes
0.05
0.04
0.03
0.02
0.01
0 -40
-20
0
20
40
60
80
100
default','3*default') hold off
0.045 0.04 0.035 0.03 0.025 0.02 0.015 0.01 0.005 0 -10 normal epanechnikov box triangle
2.常用作图函数 2.1 普通双函数图
Two Y Axes 3 3
t = 0:pi/20:2*pi; y = exp(sin(t)); plotyy(t,y,t,y,'plot','stem') xlabel('X Axis') ylabel('Plot Y Axis') title('Two Y Axes')
2.5
2.5Biblioteka 22Plot Y Axis
1.5
1.5
1
1
0.5
0.5
0
0
1
2
3 X Axis
4
5
6
0 7
2.2 多数据集在同一图中
1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 sin(x) sin(x-.25) sin(x-.5)
0
1
2
3
4
5
6
7
x = 0:pi/100:2*pi; y = sin(x); y2 = sin(x-.25); y3 = sin(x-.5); plot(x,y,x,y2,x,y3) legend('sin(x)','sin(x-.25)','sin(x-.5)')
0
0.5
1
1.5
2
2.5
3
1.14 ksdensity 概率密度估计函数
Density estimate for MPG 0.06 default width 1/3 default 3*default
cars = load('carsmall','MPG','Origin'); MPG = cars.MPG; [f,x,u] = ksdensity(MPG); plot(x,f) title('Density estimate for MPG') hold on [f,x] = ksdensity(MPG,'width',u/3); plot(x,f,'r'); [f,x] = ksdensity(MPG,'width',u*3); plot(x,f,'g'); legend('default width','1/3
plot(x,y,x,z) gtext('N(0,1)') gtext('N(0,2)') title('正态分布密度曲线')
1.2 绘出 t-分布的密度函数曲线,并与标准正态密度曲线比较
0.4 0.35 0.3 0.25
概率密度 p
t分 布 标准正态密度
0.2 0.15 0.1 0.05 0 -5
1.3 绘制开方分布密度函数在 n 分别等于 1、5、15 的图
0.2 0.18 0.16 0.14 0.12 0.1 0.08 0.06 0.04 0.02 0
x=0:1:30;y1=chi2pdf(x,1); plot(x,y1,':') hold on y2=chi2pdf(x,5);plot(x,y2,'+') y3=chi2pdf(x,15);plot(x,y3,'O') Axis([0,30,0,0.2])
0.2
0.15
0.1
0.05
0
0
1
2
3
4
5
6
7
8
9
10
1.13 指数分布函数图
2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0
lambda = 2; % Failure rate t = 0:0.01:3; % Outcomes f = exppdf(t,1/lambda); % Probability density vector plot(t,f) % Visualize the probability distribution grid on
6
6
2
0
2
4
6
8
2
1
3
7
clear; x = [1 3 7]; y = [6 9 2]; s1 = subplot(2,2,1); plot(x,y); grid;
title('Default'); s2 = subplot(2,2,2); plot(x,y); set(s2,'XTick',x); % 改变 X 轴标记 set(s2,'XGrid','on');% 画 X 轴的格栅线 title('X scale manipulated'); s3 = subplot(2,2,3); plot(x,y); set(s3,'YTick',[2,6,9]);% 改变 y 轴标记 set(s3,'YGrid','on');% 画 y 轴的格栅线 set(s3,'GridLineStyle','-.');% 使用虚线格栅 title('Y scale manipulated'); s4 = subplot(2,2,4); plot(x,y); set(s4,'XTick',x);% 改变 xy 轴标记 set(s4,'YTick',[2 6 9]); grid; % 画 xy 轴的格栅线 title('Both scales manipulated'); clf reset %Clearing the
0.3
0.25
m = binopdf(k,n,p); % Probability mass vector bar(k,m) % Visualize the probability distribution set(get(gca,'Children'),'FaceColor',[.8 .8 1]) grid on
0
5
10
15
20
25
30
1.4 计算自由度是 50,10 的 F-分布的 0.9 的分位数,并给出概率与分 位数关系的图形
概率与分位数的关系 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 2.1171 2.5 p=0.9
x=finv(0.9,50,10) p=fcdf(x,50,10) t=0:0.1:4; y=fpdf(x,50,10); z=fpdf(t,50,10); plot(t,z,[x,x],[0,y]) text(x,0,'2.1171') gtext('p=0.9')
常用 Matlab 作图命令
1.概率统计作图
1.1 绘出正态分布的密度函数曲线
正态分布密度曲线 0.4 0.35 0.3 N(0,2) 0.25 0.2 0.15 0.1 0.05 0 -5 N(0,1)