How to get arrows on axes in MATLAB plot?

前端 未结 2 1571
醉梦人生
醉梦人生 2021-02-02 02:54

I want to plot something like this:

x = 0:0.01:10;
f = @(x) 50* 1.6.^(-x-5);
g = @(x) 50* 1.6.^(+x-10);
plot(x, f(x));
hold on
plot(x, g(x));

I

2条回答
  •  佛祖请我去吃肉
    2021-02-02 03:11

    The symbolic math toolbox has provisions for making these arrows, but without that toolbox you are stuck with drawing the arrows yourself. The following code should be useful for this purpose:

    % determine position of the axes
    axp = get(gca,'Position');
    
    % determine startpoint and endpoint for the arrows 
    xs=axp(1);
    xe=axp(1)+axp(3)+0.04;
    ys=axp(2);
    ye=axp(2)+axp(4)+0.05;
    
    % make the arrows
    annotation('arrow', [xs xe],[ys ys]);
    annotation('arrow', [xs xs],[ys ye]);
    
    % remove old box and axes
    box off
    set(gca,'YTick',[])
    set(gca,'XTick',[])
    set(gca,'YColor',get(gca,'Color'))
    set(gca,'XColor',get(gca,'Color'))
    

    The only drawback is that for some figure window sizes you will have a 1-pixel white border below the arrows, and setting the LineWidth property of the axes to a ridiculous small value does not help.

    But for printing, the small white border should not be relevant.

提交回复
热议问题