www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/DisplayAxisLinesThroughOriginExample.m

    %% Display Axis Lines Through Origin
% This example shows how to create a plot and display the _x_-axis and
% _y_-axis lines so that they cross at the origin point (0,0). It also
% shows how to turn off the display of the axes outline.

% Copyright 2015 The MathWorks, Inc.


%%
% Create a line plot. By default, the _x_-axis is at the bottom of the
% graph and the _y_-axis is on the left side.
x = linspace(-10,4);
y = sin(x);
plot(x,y)

%%
% Display the axis lines so that they cross at the origin
% point (0,0). Change the location of the _x_-axis and _y_-axis by setting
% the |XAxisLocation| and |YAxisLocation| properties, respectively. 
% You can set |XAxisLocation| to either |'top'|, |'bottom'|, or |'origin'|.
% You can set |YAxisLocation| to either |'left'|, |'right'|, or |'origin'|.

ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';

%%
% Turn off the display of the axes outline by setting the |Box| property.

ax.Box = 'off';