应用举例:自动调整x,y的区间,并移动坐标原点
set(groot,'defaultAxesLineStyleOrder','remove','defaultAxesColorOrder','remove'); %每次使用记得清除上次设置的参数,否则设置的参数会被保留下来 x=1:255;y=rand(1,255);y=y';%y是行向量还是列向量都无所谓 n=length(x); stem(x,y, 'Marker', 'none'); title('未设置坐标轴的区间');
%坐标轴区间的自动设置(适用于直方图的显示)
% Get x/y limits of axes using axis
hist_axes = gca;
limits = axis(hist_axes);
if n ~= 1 %当只有一个值时设置x坐标轴
limits(1) = min(x);
else
limits(1) = 0;
end
limits(2) = max(x);
var = sqrt(y'*y/length(y));
limits(4) = 2.5*var; %只改变了y轴显示的高度
axis(hist_axes,limits);
title('设置了的坐标轴区间');
%改变图像的坐标原点(本应属于该节内容) % In GUIDE, default axes units are characters. In order for axes repositiong % to behave properly, units need to be normalized. hist_axes_units_old = get(hist_axes,'units'); set(hist_axes,'Units','Normalized'); %Get axis position and make room for others. pos = get(hist_axes,'pos'); stripe = 0.2; set(hist_axes,'pos',[pos(1) pos(2)+stripe*pos(4) pos(3) (1-stripe)*pos(4)]) set(hist_axes,'Units',hist_axes_units_old); %坐标向上移动了,相应也调整了整个图众向比例 title('移动了的坐标原点');
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)