Matlab畫圖--基礎曲線、直方圖、餅圖等

1、
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’);
在這裏插入圖片描述
2、
x=0:0.01:20;
y1=200exp(-0.05x).sin(x);
y2=0.8
exp(-0.5*x).sin(10x);
[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’,’:’);
在這裏插入圖片描述
3、
y=randn(1,1000);
subplot(2,1,1);
hist(y,10);
title(‘Bins=10’);
subplot(2,1,2);
hist(y,50);
title(‘Bins=50’);
在這裏插入圖片描述
4、bar用法
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 ');
在這裏插入圖片描述
5、
x=[1 2 5 4 8];
y=[x;1:5];
subplot(1,2,1);
bar(y,‘Stacked’);
title(‘Stacked’);

subplot(1,2,2);
barh(y);
title(‘Horizontal’);
在這裏插入圖片描述
6、pie charts
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]);
在這裏插入圖片描述
7、stairs and stem charts
x=linspace(0, 4*pi,40); y=sin(x);
subplot(1,2,1); stairs(y);
subplot(1,2,2); stem(y);
在這裏插入圖片描述
8、
(1)load carsmall
boxplot(MPG,Origin);
在這裏插入圖片描述
(2)
x=0:pi/10:pi; y=sin(x);
e=std(y)ones(size(x));
errorbar(x,y,e);
在這裏插入圖片描述
9、調顏色
G=[46 38 29 24 13]; S=[29 27 17 26 8];
B=[29 23 19 32 7]; h=bar(1:5,[G’ S’ B’]);
title(‘Medal count for top 5 countries in 2012 Olympics’);
legend(‘Gold’,‘Silver’,‘Bronze’);
在這裏插入圖片描述
(2)
[x,y]=meshgrid(-3:.2:3,-3:.2:3);
z=x.2+x.*y+y.2; surf(x,y,z); box on;
set(gca,‘FontSize’,16); zlabel(‘z’);
xlim([-4,4]); xlabel(‘x’); ylim([-4 4]); ylabel(‘y’);
在這裏插入圖片描述
(3)
imagesc(z); axis square; xlabel(‘x’); ylabel(‘y’);
在這裏插入圖片描述
進階:
[x,y]=meshgrid(-3:.2:3,-3:.2:3);
z=x.2+x.*y+y.2; surf(x,y,z); box on;
set(gca,‘FontSize’,16); zlabel(‘z’);
xlim([-4,4]); xlabel(‘x’); ylim([-4 4]); ylabel(‘y’);
imagesc(z); axis square; xlabel(‘x’); ylabel(‘y’);
colorbar;
在這裏插入圖片描述
10、
[x,y]=meshgrid(-3:.2:3,-3:.2:3);
z=x.2+x.*y+y.2; surf(x,y,z); box on;
set(gca,‘FontSize’,16); zlabel(‘z’);
xlim([-4,4]); xlabel(‘x’); ylim([-4 4]); ylabel(‘y’);
imagesc(z); axis square; xlabel(‘x’); ylabel(‘y’);
colorbar;
colormap(hot);
在這裏插入圖片描述
%colormap(cool);
%colormap(gray);
11、3D畫圖
(1)
t=0:pi/50:10
pi;
plot3(sin(t),cos(t),t)
grid on; axis square;
在這裏插入圖片描述
(2)
x=-3.5:0.2:3.5; y=-3.5:0.2:3.5;
[X,Y]=meshgrid(x,y);
Z=X.*exp(-X.2-Y.2);
subplot(1,2,1); mesh(X,Y,Z);
subplot(1,2,2); surf(X,Y,Z);
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章