Matlab绘图基础——axis设置坐标轴取值范围

Matlab绘图基础——axis设置坐标轴取值范围,第1张

Matlab绘图基础——axis设置坐标轴取值范围 peaks; axis tight  %Set the axis limits to equal the range of the data  axis square axis 'auto x'  %x轴坐标上下限自动调整 axis off    %Plot a surface without displaying the axes lines and background. set(gca,'Visible','off');   %消除坐标轴,显示范围的大小没有改变,同上句     %更多特性可参考帮助 %同时设置subplot的多幅图像的axis %Create a figure with two subplots.set the axis limits for the subplots to the same values. x1 = linspace(0,10,100);y1 = sin(x1); ax1 = subplot(2,1,1);plot(ax1,x1,y1) x2 = linspace(0,5,100);y2 = sin(x2); ax2 = subplot(2,1,2);plot(ax2,x2,y2);   axis([ax1 ax2],[0 10 -1 1]) %如果想在原图上继续作图,而不改变原坐标系的区间 x = linspace(0,10);y = sin(x);plot(x,y) y2 = 2*sin(x);hold on axis manual    %关键步骤,冻结axis 可以对比不加该语句的结果 plot(x,y2);hold off %改变坐标系的方向(指向) C = eye(10); pcolor(C) colormap summer %Reverse the coordinate system so that the y values increase from top to bottom. axis ij;   %第i行,第j列 %上下两条语句等价 set(gca,'Ydir','reverse');  

应用举例:自动调整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('移动了的坐标原点');         

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/585887.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存