进阶绘图

Logarithm Plots

当数据出现指数型变化时,如果继续使用polt的线性刻度,则低次幂部分无法完全表现出来,所以需要采用semilogx、semilogy、loglog函数来解决对数数据。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
>> x = logspace(-1,1,100);
>> y = x.^2;
>> subplot(2,2,1);
>> plot(x,y);
>> title('Plot');
>> subplot(2,2,2);
>> semilogx(x,y);
>> title('Semilogx');
>> subplot(2,2,3);
>> semilogy(x,y);
>> title('Semilogy');
>> subplot(2,2,4);
>> loglog(x,y);
>> title('Loglog');
>> set(gca,'XGrid','on');
>>

1

plotyy()

两个y轴

1
2
3
4
5
6
7
8
9
10
>> x = 0:0.01:20;
>> y1 = 200*exp(-0.05*x).*sin(x);
>> y2 = 0.8*exp(-0.5*x).*sin(10*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',':');
>>

1

Histogram

1
2
3
4
5
6
7
8
>> y = randn(1,1000); # randn得到正太分布的随机数
>> subplot(2,1,1);
>> hist(y,10);
>> title('Bins = 10');
>> subplot(2,1,2);
>> hist(y, 50);
>> title('Bins = 50');
>>

Bins是指柱形的条数

1

Bar Charts

Histogram看整体的情况, Bar Charts看个别的情况

1
2
3
4
5
6
7
8
9
10
11
12
>> x = [1 2 5 4 8];
>> y = [x;1:5];
>> subplot(1,3,1);
>> bar(x);
>> title('A bargraph of vector x');
>> subplot(1,3,2);
>> bar(y);
>> title('A bargraph of vector y');
>> subplot(1,3,3);
>> bar3(y);
>> title('A 3D bargraph');
>>

1

Pie Charts

1
2
3
4
5
6
7
a = [10 5 20 30];
subplot(1,3,1);
pie(a);
subplot(1,3,2);
pie(a, [0,0,0,1]);
subplot(1,3,3);
pie3(a, [0,0,0,1]);

1

Stairs and Stem Charts

1
2
3
4
5
6
7
>> x = linspace(0, 4*pi, 40);
>> y = sin(x);
>> subplot(1,2,1);
>> stairs(y);
>> subplot(1,2,2);
>> stem(y);
>>

1

fill()

1
2
3
4
5
6
t = (1:2:15)'*pi/8;
x = sin(t);
y = cos(t);
fill(x,y,'r');
axis square off;
text(0,0,'STOP', 'Color','w','FontSize',80,'FontWeight','bold','HorizontalAlignment','center');

1

plot3()

1
2
3
4
5
6
7
8
9
10
11
12
x = 0:0.1:3*pi;
z1 = sin(x);
z2 = sin(2*x);
z3 = sin(3*x);
y1 = zeros(size(x));
y3 = ones(size(x));
y2 = y3./2;
plot3(x, y1, z1, 'r', x, y2, z2, 'b', x, y3, z3, 'g');
grid on;
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');

1

Donate? comment?