二维图

Task08 二维图
语法知识
5.1线型图函数plot
可以用来啊绘制散点图,序列图,向量图,矩阵图和函数图等。设置线的类型(LineStyle),改变颜色(color),线的宽度(LineWidth),设置标记(marker)。
plot(x,y)x为横坐标,y为纵坐标。
5.2简易线性函数图
ezplot(f,[xmin,xmax,ymin,ymax])
f为符号函数表达式,[xmin,xmax,ymin,ymax]x.yd的变化区间。
5.3散点图
scatter(x,y,s,c)x,y是横纵坐标向量,s为面积,c为标记点颜色。
5.4极坐标图及其与直角坐标图的转换
polar(t’heta,rho)theta是极坐标的角度,rho为模长。
5.5条形图
bar(x,y)。
5.6饼图
pie(X,explode) 将向量中某几个元素从饼图总分离出来。explode与x是同维向量。
5.7阶梯图
stairs(x,y)。
5.8茎秆图
steam(x,y)。
5.9平行多边形的作色
fill(x,y,c)。

演练过程
例5.1

Y=fix(100*rand(1,8))
Y =
81 90 12 91 63 9 27 54

plot(Y)
grid on ; %增加坐标格栅线
%
title(‘向量y的线型图’)
xlabel(‘向量y的下标’) %设置横坐标标注
ylabel(‘向量y的各元素值’) %设置纵坐标标注

例5.2

syms x; %设置符号变量
y=atan(x);%建立反正切符号表达式
y1=diff(y)%建立反正切函数的微分 diff为微分函数
y1 =
1/(x^2 + 1)

x=-5:0.1:5;
y=eval(y);%执行正切函数的计算
y1=1./(1+x.^2);%计算微分曲线的值
plot(x,y,’-’,x,y1,’*’)
grid on
title(‘反正切函数及其微分曲线’)
xlabel(‘x坐标’)
ylabel(‘y坐标’)

5.3
5.4

x=0:pi/50:2*pi;
y=sin(x);
h=plot(x,y)
set(h,‘LineWidth’,8,‘color’,‘r’)
grid on

5.5

t=0:pi/50:4pi;
I=sin(t);
V=2
sin(t+pi/3);
P=I.*V;
plot(t,I,’-’,t,V,’:’,t,P,’+’);grid on

5.6

time=[0:0.02:10]’;
u=1.0*(1+0*(time));
for i=min(find(time>=2.0)):length(u)
u(i)=2.0;
end

plot(time,u)
axis([0,10,0,1.2])%设置坐标范围

5.7

ezplot(‘x2/9+y2/4-1’)
axis([-3,3,-2,2]),grid on

5.8

ezplot(‘cos(2x)./(1-sin(2x)^(1/2))’)
grid on

5.9

X=[1.55,1.58,1.6,1.64,1.66,1.68,1.7,1.73,1.78,1.8,1.82,1.85];
Y=[60,57,57,65,63,64,70,65,68,76,72,78];
plot(X,Y,‘b*’)
hold on
polyfit(X,Y,1)%取一阶线性回归
ans =
63.2899 -41.2900

x=1.5:0.1:2;
y=-41.29+63.2899*x;
plot(x,y,‘r-’)
grid on
xlabel(‘height’)
ylabel(‘weight’)
title(‘the relationship of height and weight’)

5.10

A=[0.25,0.5,0.75,1,2,3,4,5,6,6.5,7;4,3,2,1,0,0,1,0,1,3,6]
A =
1 至 5 列
0.2500 0.5000 0.7500 1.0000 2.0000
4.0000 3.0000 2.0000 1.0000 0
6 至 10 列
3.0000 4.0000 5.0000 6.0000 6.5000
0 1.0000 0 1.0000 3.0000
11 列
7.0000
6.0000

t=A(1,1:11);%从矩阵中提取故障时间向量
faunum=A(2,1:11);%从矩阵中提取故障次数向量
t1=0:0.1:7;
fauspl=interp1(faunum,t1,‘spline’);%用三次条样插值连接故障点
plot(t,faunum,‘o’,t1,fauspl)

5.11

A=[2001 2005 2010 2020 2050;12.76 13.3 14 15 16]
A =
1.0e+03 *
2.0010 2.0050 2.0100 2.0200 2.0500
0.0128 0.0133 0.0140 0.0150 0.0160

year=A(1,:)
year =
1 至 4 列
2001 2005 2010 2020
5 列
2050

popu=A(2,:)%从矩阵提取人口向量
popu =
12.7600 13.3000 14.0000 15.0000 16.0000

t=2001:0.2:2050;
fspl=interpl(year,popu,t,‘spline’);
未定义函数或变量 ‘interpl’。

fspl=interp1(year,popu,t,‘spline’);
plot(year,popu,‘o’,t,fspl);grid on

5.12

% this program for draw a scatter flower
for r=2:20
zeta=0:pi/12:2pi;
x=r
cos(zeta+rpi/30);
y=r
sin(zeta+r*pi/30);
c(1)=2/r;c(2)=r/20;c(3)=r/20;
scatter(x,y,5,c,‘filled’)
hold
end

5.13

zeta=0:6pi/600:6pi;
r=sin(3*zeta);
[x,y]=pol2cart(zeta,r);
subplot(1,2,1);polar(zeta,r)
subplot(1,2,2);plot(x,y);grid on

5.14

zeta=0:pi/20:4*pi;
x=cos(zeta).^3’;

y=sin(zeta).^3;
[theta,rho]=cart2pol(x,y);
h=polar(theta,rho)

5.15

x=0:pi/20:5/2pi;
y=exp(-0.5
x).*cos(x);
bar(y,0.5)

5.16

Y=magic(4);
subplot(1,2,1)
bar(Y)
subplot(1,2,2)
bar(Y,‘stacked’)

5.17

A=[150 50 12 3];
B=[150000 75000 48000 30000];
subplot(1,2,1);pie(A[1,0,0,0])
subplot(1,2,1);pie(A,[1,0,0,0])
subplot(1,2,2);pie(B,[1,0,0,0])

5.18

X=[800 1000 1200 1500 2000 2500 3500 5000 ];
Y=[10 13 21 33 12 8 2 1];
h=stairs(X,Y)

5.19

x=1:12;
y=exp(-0.5*x).sin(x);
stem(y)
hold on
x1=0:0.1:12;
y1=exp((-0.5
x1).*sin(x1));
plot(x1,y1,‘k’)

5.20

t=pi/16:pi/8:2*pi;
x=cos(t);
y=sin(t);
fill(x,y,‘m’),axis square

学习心得
1.学习了二维图。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值