视频
拓展学习
例1 绘制1/的直角线性坐标图和三种对数坐标图。
x=0:0.1:10;
y=1./x;
subplot(2,2,1)
plot(x,y)
title('plot(x,y)');grid on
subplot(2,2,2)
semilogx(x,y)
title('semilogx(x,y)');grid on
subplot(2,2,3)
semilogy(x,y)
title('semilogy(x,y)');grid on
subplot(2,2,4)
loglog(x,y)
title('loglog(x,y)');grid on
例2 按极坐标方程ρ=1-sin t绘制心形曲线。
t = 0:pi/100:2*pi;
r = 1-sin(t);
subplot(1,2,1)
polar(t,r)
subplot(1,2,2)
t1 = t-pi/2;
r1 = 1-sin(t1);
polar(t,r1)
例3 绘制分组条形图。
y=[1,2,3,4,5; 1,2,1,2,1; 5,4,3,2,1];
subplot(1,2,1)
bar(y)
title('Group')
subplot(1,2,2)
bar(y, 'stacked')
title('Stack')
例4 下表是某公司2015~2017年家电类商品1月份的销售数据,绘制条形图对比数据。
x=[2015,2016,2017];
y=[68,80,115,98,102;
75,88,102,99,110;
81,86,125,105,115];
bar(x, y)
title('Group');
例5 绘制服从高斯分布的直方图。
y=randn(500,1);
subplot(2,1,1);
hist(y);
title('高斯分布直方图');
subplot(2,1,2);
x=-3:0.2:3;
hist(y,x);
title('指定区间中心点的直方图')')
例6 绘制高斯分布数据在极坐标下的直方图。
y=randn(500,1);
theta=y*pi;
rose(theta)
title('在极坐标下的直方图')
例7 某次考试优秀、良好、中等、及格、不及格的人数分别为:7、17、23、9、4,试用扇形统计图作成绩统计分析。
score = [5, 17, 23, 9, 4];
ex = [0,0,0,0,1];
pie(score, ex)
legend('优秀', '良好', '中等’, '及格', '不及格', …
'location', 'eastoutside')
例8 以散点图形式绘制桃心曲线
t = 0:pi/50:2*pi;
x = 16*sin(t).^3;
y = 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t);
scatter(x,y,'rd','filled')
例9 已知向量A、B,求A+B,并用矢量图表示。
A=[4,5]; B=[-10,0]; C=A+B;
hold on;
quiver(0, 0, A(1), A(2));
quiver(0, 0, B(1), B(2));
quiver(0, 0, C(1), C(2));
text(A(1),A(2),'A');text(B(1),B(2),'B'); text(C(1),C(2),'C');
axis ([-12, 6, -1, 6])
grid on

