Matlab绘制自然原点坐标的坐标轴

来源:互联网 发布:hottoys淘宝店哪些靠谱 编辑:程序博客网 时间:2024/04/28 15:54
standard_axes函数, 可以将函数的坐标轴按照自然原点坐标显示
======================================================function varargout = standard_axes(axes_handle)% STANDARD_AXES 创建标准坐标系% STANDARD_AXES 将当前坐标系转换为标准坐标系% STANDARD_AXES(H) 将由H指定的坐标系转换为标准坐标系% AX = STANDARD_AXES(...) 返回转换后的标准坐标系的横轴和纵轴的句柄向量% [AX1,AX2] = STANDARD_AXES(...) 返回转换后的标准坐标系的横轴句柄和纵轴句柄% 输入参数:%     ---H,指定的坐标轴句柄% 输出参数:%     ---AX,AX1,AX2, 标准坐标系的横轴和纵轴句柄%% See also axes, annotationif nargin == 0    axes_handle = gca;endpos = get(axes_handle,'Position');x_Lim = get(axes_handle,'Xlim');y_Lim = get(axes_handle,'Ylim');x_Scale = get(axes_handle,'XScale');y_Scale = get(axes_handle,'YScale');color = get(gcf,'Color');if prod(y_Lim)>0    position_x = [pos(1), pos(2)+pos(4)/2, pos(3), eps];else    position_x = [pos(1), pos(2)-y_Lim(1)/diff(y_Lim)*pos(4), pos(3), eps];endaxes_x = axes('Position', position_x,'Xlim',x_Lim,'Color',color,...    'XScale',x_Scale,'YScale',y_Scale);if prod(x_Lim)>0    position_y = [pos(1)+pos(3)/2, pos(2), eps, pos(4)];else    position_y = [pos(1)-x_Lim(1)/diff(x_Lim)*pos(3), pos(2), eps, pos(4)];endaxes_y = axes('Position', position_y, 'Ylim', y_Lim, 'Color', color, ...    'XScale', x_Scale, 'YScale', y_Scale);set(axes_handle, 'Visible', 'off')annotation('arrow', [pos(1)-0.065*pos(3), pos(1)+pos(3)+0.065*pos(3)], ...    [position_x(2)-0.001,position_x(2)-0.001],'HeadLength',6,'HeadWidth',6);annotation('arrow', [position_y(1)+0.001, position_y(1)+0.001],...    [pos(2)-0.065*pos(4),pos(2)+pos(4)+0.065*pos(4)],...    'HeadLength',6,'HeadWidth',6);if nargout == 1    varargout{1} = [axes_x,axes_y];elseif nargout == 2    varargout{1} = axes_x; varargout{2} = axes_y;elseif nargout > 2    error('Too many output arguments.');end
==========================================================


>>  hAxes1=axes('Position', [0.13,0.58,0.77,0.34]);
>>  T = linspace(-2*pi,2*pi,10);
>> h = stem(T,cos(T),'fill','--');
>> set(get(h,'BaseLine'),'LineStyle',':');
>> set(h,'MarkerFaceColor','red');
>> standard_axes(hAxes1)
>> hAxes2=axes('Position', [0.13,0.11,0.33,0.34]);
>> t=0:0.01:2*pi;
>> x=5*(2*cos(t)-cos(2*t));
>> y=5*(2*sin(t)-sin(2*t));
>> plot(x,y);
>> standard_axes(hAxes2)
>> hAxes3=axes('Position', [0.57,0.11,0.33,0.34]);
>> hz=[20:10:100,200:100:1000,1500,2000:1000:10000];
>> spl =[76,66,59,54,49,46,43,40,38,22,14,9,6,3.5,2.5,1.4,0.7,0,-1,-3,-8,-7,-2,2,7,9,11,12];
>> semilogx(hz,spl,'k-o');
>> standard_axes(hAxes3)
0 0
原创粉丝点击