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

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, annotation

if nargin == 0
    axes_handle = gca;
end
pos = 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];
end
axes_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)];
end

axes_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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值