六、Matlab 之 绘图操作(下)

来源:互联网 发布:windows bat脚本sleep 编辑:程序博客网 时间:2024/06/05 06:11

1、对数函数的一些操作

x = logspace(-1, 1, 100);  从10^-1 - 10^1之间的100个点y = x.^2;subplot(2,2,1); %subplot 是把多个图形画在一个平面上,此处表示的意思就是共两行两列,我这个图形在第一个plot(x,y); title('Plot');subplot(2,2,2);semilogx(x,y); %对x取对数,就是x变成了从-1 ~ 1的范围title('scmilogx');subplot(2,2,3);semilogy(x,y);title('scmilogy'); %对y取对数subplot(2,2,4);loglog(x, y); %表示对x和y都取对数title('Loglog');

2、plotyy的实例

x = 0:0.01:20;y1 = 200*exp(-0.05*x).*sin(x);y2 = 0.8*exp(-0.5*x).*sin(x);[AX, H1, H2] = plotyy(x,y1, x, y2);set(get(AX(1), 'Ylabel'), 'String', 'Left Y-axis');set(get(AX(2), 'Ylabel'), 'String', 'Right Y-axis');title('Labeling plotyy');set(H1, 'LineStyle', '--'); set(H2, 'LineStyle', ':');

其实也很简单,就是一个坐标画了两个图形,两个y值。

3、统计图的绘制

y = randn(1, 1000);subplot(2, 1, 1);hist(y, 10); %分成10个title('统计图')

比较有意思的就属这个hist函数了,表示你要分几个。

4、bar charts的玩法

x =[1 2 5 6 7]; y=[x; 1:5];subplot(1,3, 1); bar(x); subplot(1,3, 2); bar(y);subplot(1,3, 3); bar3(y);

我觉得图更好看点,,,上图、
这里写图片描述

压栈操作更是一种骚气。。

x =[1 2 5 6 7]; y=[x; 1:5];subplot(1,3, 1); bar(x,'stacked'); subplot(1,3, 2); bar(y,'stacked');subplot(1,3, 3); bar3(y,'stacked');

这里写图片描述

倒过来显示的话,那就是

barh(y,'stacked');

5、扇形图

x = [10 20 30 5];subplot(1,3,1); pie(x);subplot(1,3,2); pie(x, [0 0 0 1]);subplot(1,3,2); pie(x, [0,0,0,1]);subplot(1,3,3); pie3(x, [0 0 0 1]);
原创粉丝点击