Matlab学习笔记7 高阶绘图

画多个图

x = logspace(-1,1,100); %这个语句表示从10的-1次方到1次方,100个数

y = x.^2;

subplot(2,2,1); %使用subplot语句可以在一个Figure中画多个子图

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');


%plotyy,在一个图中有两个y轴,可以在一个图上呈现两个图

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',':');


%Histogram,画直方图,看数据的分布形态

y = randn(1,1000);

subplot(2,1,1);

hist(y,10); %10d的意思就是有10个bin

title('Bins = 10');

subplot(2,1,2);

hist(y,50);

title('Bins = 50');


%Bar chat,直方图是一种很powerful的数据呈现形式

x = [1 2 5 4 8];

y = [x;1:5];

subplot(2,3,1);

bar(x);

title('A bargraph of vector x');

subplot(2,3,2);

bar(y);

title('A bargraph of vector y');

subplot(2,3,3);

bar3(y); %bar3可以画3D的图

title('A 3D bargraph');

subplot(2,3,4);

bar(y,'stacked');%stacked将所有的数据叠加起来显示

title('Stacked');

subplot(2,3,5);

barh(y); %将bar横过来画图

title('Horizontal');


%Pie charts,显示不同数据的比例

a = [10 5 20 30];

subplot(2,2,1);

pie(a);

subplot(2,2,2);

pie(a,[0,0,0,1]); %后面中括号里的1代表将这个部分裂开

subplot(2,2,3);

pie3(a,[0,0,0,1]);

subplot(2,2,4);

pie3(a,[1,1,1,1]);


%Boxplot with Error bar

load carsmall

subplot(1,2,1);

boxplot(MPG,Origin);

x = 0:pi/10:pi;

y = sin(x);

e = std(y)*ones(size(x));

subplot(1,2,2);

errorbar(x,y,e); %e代表的是errorbar


%Polar chart

x = 1:100;

theta = x/10;

r = log10(x);

subplot(2,2,1);

polar(theta,r);

theta = linspace(0,2*pi);

r = cos(4*theta);

subplot(2,2,2);

polar(theta,r);

theta = linspace(0,2*pi,6);

r = ones(1,length(theta));

subplot(2,2,3);

polar(theta,r);

theta = linspace(0,2*pi);

r = 1-sin(theta);

subplot(2,2,4);

polar(theta,r);


%要先画一个八边形,先确定每一个角的度数,然后根据度数,可以算出每一个角的坐标x和y

t = (1:2:15)'*pi/8;

x = sin(t);

y = cos(t);

fill(x,y,'r'); %fill来画出x和y围成的8边形的形状,并用红色来进行填充

axis square off; %去掉坐标轴

text(0,0,'STOP','Color','w','FontSize',80,...

    'FontWeight','bold','HorizontalAlignment','center'); %设置中间的字符,字号,是否粗体等属性


%Display vakues of a matrix as an "image"

[x, y] = meshgrid(-3:.2:3,-3:.2:3);

z = x.^2 + x.*y + y.^2;

imagesc(z);

axis square;

xlabel('x');

ylabel('y');

colorbar;

colormap(pink); %hot,gray,pink,


接下来是画3D的图,可能会用到如下的指令:

plot3(); 3D line plot

surf(); 3D shaded surface plot

surfc(); Contour plot under a 3D shaded surface plot

surface(); Create surface object

meshc(); Plot a contour graph under mesh graph

contour(); Contour plot of matrix

contourf(); Filled 2D contour plot

你可能感兴趣的:(Matlab学习笔记7 高阶绘图)