1. Matlab自帶繪圖函數(shù),坐標(biāo)軸不帶箭頭,如下所示:
使用系統(tǒng)函數(shù)繪圖,在生成的圖形上疊加兩個annotation對象表示x軸和y軸,定義對象位置和樣式使其顯示為帶箭頭坐標(biāo)軸的樣子。
3.
函數(shù)m文件及測試文件下載地址: http://ishare.iask.sina.com.cn/f/66484659.html
4. 測試1:帶箭頭屬性繪圖 clc
clear
x
y
Attribute_Set = {'LineWidth',1.5};
[h h_a h_p h_arrow] = plot_with_arrow( [],x,y,'k',[],[],Attribute_Set
);
htext_x = Arrow_Xlabel([],'時間/s',[]);
htext_y = Arrow_Ylabel([],'幅值/V',[]);
htext_title = Arrow_Title([],'圖形Test'); 測試2:用數(shù)值指示箭頭坐標(biāo)軸位置 clc clear x y figure ha1 =
subplot(211); pos = [0.1
0.7 1 1 0.1 0.7]; [h h_a h_p
h_arrow] = plot_with_arrow( ha1,x,y,'k',pos
); htext_x = Arrow_Xlabel([],'時間/s',pos); htext_y = Arrow_Ylabel([],'幅值/V',pos); htext_title = Arrow_Title([],'圖形Test'); ha2 =
subplot(212); pos = [0.8
0.2 0.1 0.6 0.8 0.2]; [h h_a h_p
h_arrow] = plot_with_arrow( ha2,x,y,'k',pos
); htext_x = Arrow_Xlabel([],'時間/s',pos); htext_y = Arrow_Ylabel([],'幅值/V',pos); htext_title = Arrow_Title([],'圖形Test');
clc clear x y h_f =
figure; [h h_a h_p]
= plot_with_arrow( h_f,x,y,'k'
); htext_x = Arrow_Xlabel([],'時間/s',[]); htext_y = Arrow_Ylabel([],'幅值/V',[]); htext_title = Arrow_Title([],'圖形Test'); 測試4:輸入坐標(biāo)軸句柄 clc clear x y figure h_a =
subplot(211); [h h_a h_p] = plot_with_arrow( h_a,x,y,'k' ); htext_x = Arrow_Xlabel([],'時間/s',[]); htext_y = Arrow_Ylabel([],'幅值/V',[]); htext_title = Arrow_Title([],'圖形Test1'); h_a2 =
subplot(212); [h h_a h_p] = plot_with_arrow( h_a2,x,y,'k','nn' ); htext_x = Arrow_Xlabel([],'時間/s','nn'); htext_y = Arrow_Ylabel([],'幅值/V','nn'); htext_title = Arrow_Title([],'圖形Test2');
clc clear x = -2.9:0.2:2.9; y = exp(-x.*x); figure h_a = subplot(211); [h h_a h_p
h_arrow] = plot_with_arrow( h_a,x,y,'r',[],@bar
); htext_x = Arrow_Xlabel([],'時間/s',[]); htext_y = Arrow_Ylabel([],'幅值/V',[]); htext_title = Arrow_Title([],'圖形Test1'); h_a2 = subplot(212); [h h_a h_p
h_arrow] = plot_with_arrow( h_a2,x,y,'b',[],@stem
); htext_x = Arrow_Xlabel([],'時間/s',[]); htext_y = Arrow_Ylabel([],'幅值/V',[]); htext_title = Arrow_Title([],'圖形Test2'); 測試6:繪制光坐標(biāo)軸,hold on之后再繪制圖形 pos = 'an'; [h ha hp
h_arrow] hold on t = linspace(0,4*pi,200); x = sin(t); plot(t,x) htext_x = Arrow_Xlabel([],'時間/s',pos); htext_y = Arrow_Ylabel([],'幅值/V',pos); htext_title = Arrow_Title([],'圖形Test');
clc clear x y figure h_a1 = subplot(221); [h1 h_a1
h_p1 h_arrow1] = plot_with_arrow( h_a1,x,y,'r'
); htext_x1 = Arrow_Xlabel([],'時間/s',[]); htext_y1 = Arrow_Ylabel([],'幅值/V',[]); h_a2 = subplot(222); pos2 = 'an'; [h2 h_a2
h_p2 h_arrow2] = plot_with_arrow( h_a2,x,y,'r',pos2
); htext_x2 = Arrow_Xlabel([],'時間/s',pos2); htext_y2 = Arrow_Ylabel([],'幅值/V',pos2); h_a3 = subplot(223); pos3 = 'nn'; [h3 h_a3
h_p3 h_arrow3] = plot_with_arrow( h_a3,x,y,'r',pos3
); htext_x3 = Arrow_Xlabel([],'時間/s',pos3); htext_y3 = Arrow_Ylabel([],'幅值/V',pos3); h_a4 = subplot(224); pos4 = 'np'; [h4 h_a4
h_p4 h_arrow4] = plot_with_arrow( h_a4,x,y,'r',pos4
); htext_x4 = Arrow_Xlabel([],'時間/s',pos4); htext_y4 = Arrow_Ylabel([],'幅值/V',pos4); 測試8:坐標(biāo)調(diào)整 當(dāng)坐標(biāo)軸中的子對象(如曲線等)被Label對象擋住時,可通過axis或xlim、ylim調(diào)整坐標(biāo)軸位置來消除這種影響 也可通過h_text_x/y句柄或是通過鼠標(biāo)手動調(diào)整Label對象的位置 clc clear x y figure h_a1 = subplot(221); [h1 h_a1 h_p1 h_arrow1] = plot_with_arrow( h_a1,x,y,'r','pa' ); htext_x1 = Arrow_Xlabel([],'時間/s','pa'); htext_y1 = Arrow_Ylabel([],'幅值/V','pa'); htext_title1 = Arrow_Title(h_a1,'調(diào)整前'); h_a2 = subplot(222); [h2 h_a2 h_p2 h_arrow2] = plot_with_arrow( h_a2,x,y,'b','pa' ); htext_x2 = Arrow_Xlabel([],'時間/s','pa'); htext_y2 = Arrow_Ylabel([],'幅值/V','pa'); htext_title2 = Arrow_Title(h_a2,'調(diào)整后'); axes(h_a2) axis([0 12
-1.5 1.5]) h_a3 = subplot(223); pos3 = 'nn'; [h3 h_a3 h_p3 h_arrow3] = plot_with_arrow( h_a3,x,y,'r',pos3 ); htext_x3 = Arrow_Xlabel([],'時間/s',pos3); htext_y3 = Arrow_Ylabel([],'幅值/V',pos3); htext_title3 = Arrow_Title(h_a3,'調(diào)整前'); h_a4 = subplot(224); [h4 h_a4 h_p4 h_arrow4] = plot_with_arrow( h_a4,x,y,'b',pos3 ); htext_x4 = Arrow_Xlabel([],'時間/s',pos3); htext_y4 = Arrow_Ylabel([],'幅值/V',pos3); htext_title4 = Arrow_Title(h_a4,'調(diào)整后'); axes(h_a4) axis([-2 10
-1.5 1]) 測試9:修改箭頭屬性 x y h_f = figure; [h h_a h_p
h_arrow] = plot_with_arrow( h_f,x,y,'k'
); htext_x = Arrow_Xlabel([],'時間/s',[]); htext_y = Arrow_Ylabel([],'幅值/V',[]); % 改變顏色 set( h_arrow,'color','r' ) % 修改箭頭類型 set( h_arrow,'HeadStyle','vback3' )
5.
博文為原創(chuàng),歡迎轉(zhuǎn)載,轉(zhuǎn)載注明出處,謝謝! 有Matlab/Simulink方面的技術(shù)問題,歡迎發(fā)送郵件至944077462@qq.com討論。 |
|