数学建模--画图
数学建模--画图图形可以使数据更直观且容易理解,在数学建模中画图是不可少的。
平台
win7
matlab7.0
先介绍最常用的画图函数plot:
创建数据
X = 0:0.01:10
Y = sin(X)
1
2
画第一个图
plot(X,Y)
1
设置坐标轴
set(gca,'XTick',-pi:pi/2:4*pi)
1
并设置坐标轴标签
set(gca,'XTickLabel',{'0','pi/2','pi','3pi/2','2pi','5pi/2','3pi'})
1
增加xy轴标签及标题
xlabel('-\pi \leq \Theta \leq \pi')
ylabel('sin(\Theta)')
title('Plot of sin(\Theta)')
1
2
3
增加网格线
grid on
1
取消网格线
grid off
1
固定xy轴比例,使xy轴不会因缩减放大而改变形状
axis square
1
plot还有其他形式
plot(X,Y,'r*')
曲线以红色*方式显示
1
2
坐标轴按指数次数项作为间隔
x = logspace(-1,2);
loglog(x,exp(x),'-s')
1
2
双y坐标
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
= plotyy(x,y1,x,y2,'plot');
1
2
3
4
画三维图
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t)
grid on
axis square
1
2
3
4
在同一窗口显示多个图表
income = ;
outgo = ;
subplot(2,1,1); plot(income)
subplot(2,1,2); plot(outgo)
1
2
3
4
直方图
x = -2.9:0.2:2.9;
bar(x,exp(-x.*x),'b')
1
2
丰富的直方图
Y = round(rand(5,3)*10);
subplot(2,2,1)
bar(Y,'group')
title 'Group'
%将Y的行向量作为一组叠加到一条柱上
subplot(2,2,2)
bar(Y,'stack')
title 'Stack'
%水平显示
subplot(2,2,3)
barh(Y,'stack')
title 'Stack'
%固定宽度的柱
subplot(2,2,4)
bar(Y,1.5)
title 'Width = 1.5'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
饼状图
pie(,{'North','South','East','West'})
1
将某部分抽离显示
pie(,,{'North','South','East','West'})
1
参考资料
《matlab官方手册》
---------------------
作者:Jerry_Ng
来源:CSDN
原文:https://blog.csdn.net/qq_32412759/article/details/77887101
来看看哈。。。
页:
[1]