54.二维柱状图
>> x=rand(1,5);
bar(x)
55.三维曲面绘图
[t,s]=meshgrid(0:0.1*pi:2*pi);
x=sin(t).*cos(s);
y=cos(t).*sin(s);
z=cos(2*t).*cos(2*s);
subplot(1,2,1)
mesh(x,y,z)
subplot(1,2,2)
surf(x,y,z)
56.离散数据点插值绘图,样条差值
x=sort(rand(1,10));
y=sort(rand(1,10));
X=linspace(0,1,100);
Y=spline(x,y,X);
plot(x,y,'b*',X,Y,'g')
57.半对数坐标轴绘图
x=-1:0.1:1;
y=exp(x).*cos(x);
subplot(2,1,1)
semilogy(x,y,'b-.')
subplot(2,1,2)
plot(x,y,'r-.')
58.二维和三维饼图
x=rand(1,5)
subplot(1,2,1)
pie(x)
subplot(1,2,2)
pie3(x,[0 1 0 1 0])
%[]中的1表示分离出来该部分
59.二维和三维等高线图
z=peaks;
subplot(2,2,1)
contour(z)
subplot(2,2,3)
contourf(z)
subplot(2,2,2)
contour3(z,20)
subplot(2,2,4)
surfc(z)
60.二维和三维散点图
x=rand(1,15);
y=rand(1,15);
z=rand(1,15);
subplot(1,2,1)
scatter(x,y,'r*')
subplot(1,2,2)
scatter3(x,y,z,'bo')
61.二元函数peaks绘图
peaks
surf(peaks)
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2)
62.二元匿名函数绘图
ezsurf(@(x,y)(x.^2-y.^2),[-1 1 -1 1])
63.绘制sin函数
fplot(@sin,[0,2*pi])
64.绘制匿名函数
fhd=@(x)(x.^2+1./x.^2);
fplot(fhd,[0.5 1.5])
65.极坐标函数绘图
ezpolar('3*sin(t)-3*cos(t)',[-2 2])
66.简易绘制隐函数
ezplot('x.^3.*y+x.*y^3=5',[-5 5])
67.离散数据点拟合绘图
x=sort(rand(1,10));
y=sort(rand(1,10));
p=polyfit(x,y,2)
Y=polyval(p,x);
plot(x,y,'b*',x,Y,'g')
68.离散数据点直接绘图
x=sort(rand(1,10));
y=sort(rand(1,10));
plot(x,y)
69.三维曲线绘图
t=0:2*pi;
x=cos(t).*sin(t);
y=2+t;
z=t.^2;
plot3(x,y,z)
70.三维柱状图bar3h
x=rand(3,5)
bar3h(x,'stack')
71.双对数坐标轴绘图
x=0:100;
y=exp(x);
loglog(x,y)
72.双纵轴绘图
x=-1:0.1:1;
y=x.^3;
z=x.^2;
plotyy(x,y,x,z)
73.直方图
x=randn(1,1000);
hist(x,20)
74.图像窗口标注
>> title('hist') %设置标题
>> axis([-4 4 0 130]) %设置横纵坐标
>> legend('hist') %设置图例
>> gtext('hist') %在任意位置添加标注
text(x,y,'sting') %在指定坐标位置添加标注
hold on %保持图像不关闭
hod off
grid on %打开网格线
grid off
echo on %代码回显
echo off
axis square %设置网格为正方形
plot(x,y,'r.')
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
v triangle (down)
^ triangle (up)
> triangle (right)
p pentagram
h hexagram
eg:
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
subplot(m,n,k) %一个窗口画多幅子图像
figure(n) %新打开一个窗口
plot(x,y1,x,y2)= plot(x,[y1' y2'])
75
waitbr %进度条
eg:
>> h = waitbar(0,'Please wait...');
for i=1:100
for j=1:100
waitbar(i/100)
end
end
close(h)