在matlab图形的X轴刻度添加字符串(汉字)并旋转一定角度的程序

标签:
matlabxtickxticklabel |
分类: 教育 |
在matlab图形中,有时为了特定的需要,须在X轴刻度上添加汉字,并旋转一定的角度.特将网络的程序作了一定修改以便于运用,现将程序写在下面:
function
th=rotateticklabel(h,rot,demo)
%ROTATETICKLABEL rotates tick
labels
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
if nargin==3
end
%set the default rotation if user doesn't
specify
if nargin==1
end
%make sure the rotation is in the range 0:360
(brute force method)
% while rot>360
%
% end
% while rot<0
%
% end
%get current tick labels
%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
else
end
如果要在画出的图形X轴上添加文字,并将文字旋转一定角度,下面的例子可以借鉴:
x1=[1,2,3,4,5];
x2=[2,5,1,5,6];
h=plot(x1,x2,'LineWidth',2);
set(gca,'XTick',[1 2 3 4 5]);%在X轴上设置刻度
set(gca,'XTicklabel',{'名称一','名称二','名称三','名称四','名称五'},'FontSize',15);
%在X轴上设置的对应刻度位置标上字符串,注意要和上面一一对应
h = gca;
th=rotateticklabel(h, 45);
所画出来的图形如下(本程序经调试,可以运行).
http://s10/mw690/5ffde3d3gx6DbZ0VHJv89&690