Matlab學習筆記三:繪圖

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 (left)
                               >     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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章