matlab 繪圖-橫座標角度旋轉
阿新 • • 發佈:2018-12-13
matlab繪圖設定橫座標數值的角度
matlab自帶的包中無法改變橫座標的角度,但往往橫座標的數值過長,容易造成重合,因此需要將橫座標的數值角度進行旋轉:
- 橫座標旋轉角度函式
- 呼叫方法
- 結果展示
橫座標旋轉角度函式
function th=rotateticklabel(h,rot,demo) %ROTATETICKLABEL rotates tick labels % TH=ROTATETICKLABEL(H,ROT) ris the calling form where H is a handle to % the axis that contains the XTickLabels that are to be rotated. ROT is % an optional parameter that specifies the angle of rotation. The default % angle is 90. TH is a handle to the text objects created. For long % strings such as those produced by datetick, you may have to adjust the % position of the axes so the labels don't get cut off. % % Of course, GCA can be substituted for H if desired. % % TH=ROTATETICKLABEL([],[],'demo') shows a demo figure. % % Known deficiencies: if tick labels are raised to a power, the power % will be lost after rotation. % % See also datetick. % Written Oct 14, 2005 by Andy Bliss % Copyright 2005 by Andy Bliss if nargin==3 x=[now-.7 now-.3 now]; y=[20 35 15]; figure plot(x,y,'.-') datetick('x',0,'keepticks') h=gca; set(h,'position',[0.13 0.35 0.775 0.55]) rot=90; end %set the default rotation if user doesn't specify if nargin==1 rot=90; end %make sure the rotation is in the range 0:360 (brute force method) % while rot>360 % rot=rot-360; % end % while rot<0 % rot=rot+360; % end %get current tick labels a=get(h,'XTickLabel'); %erase current tick labels from figure set(h,'XTickLabel',[]); %get tick label positions b=get(h,'XTick'); c=get(h,'YTick'); %make new tick labels if rot<180 th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','right','fontsize',14,'fontweight','bold','rotation',rot); else th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','left','fontsize',14,'rotation',rot); end
呼叫方法
在圖繪製結束之後直接利用函式
th = rotationticklabel(gca,30) %30代表旋轉30度
即可將橫座標旋轉30度
##結果展示
到目前為止,橫座標實現了旋轉的效果