天天看點

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

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

2、

x=0:0.01:20;

y1=200exp(-0.05x).sin(x);

y2=0.8exp(-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’,’:’);

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

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

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

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

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

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

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

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

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

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

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

8、

(1)load carsmall

boxplot(MPG,Origin);

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

(2)

x=0:pi/10:pi; y=sin(x);

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

errorbar(x,y,e);

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

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

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

(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’);

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

(3)

imagesc(z); axis square; xlabel(‘x’); ylabel(‘y’);

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

進階:

[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;

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

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

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

%colormap(cool);

%colormap(gray);

11、3D畫圖

(1)

t=0:pi/50:10pi;

plot3(sin(t),cos(t),t)

grid on; axis square;

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

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

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

繼續閱讀