This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Synchronize limits of specified 2-D axes




Use linkaxes to synchronize the individual axis limits across several figures or subplots within a figure. Calling linkaxes makes all input axes have identical limits. Linking axes is best when you want to zoom or pan in one subplot and display the same range of data in another subplot.

    Note:   Use linkaxes for Cartesian axes that remain in 2-D views.

linkaxes(ax) links the x- and y-axis limits of the axes specified in the vector ax. You can link any number of existing plots or subplots. The ax input should be a vector of Cartesian axes objects. Entering an array of values results in an error message.

linkaxes(ax,'option') links the axes' ax according to the specified option. The 'option' argument can be one of these values:


Link x-axis only.


Link y-axis only.


Link x-axis and y-axis.


Remove linking.

See the linkprop function for more advanced capabilities that allow you to link object properties on any graphics object.


collapse all

Create a figure with three subplots and plot data in each subplot. Link the x-axes and y-axes for the three subplots. The linkaxes function uses the limits from the first axes passed to it. Panning or zooming into one of the subplots displays the same range of data in the other two subplots.

ax1 = subplot(2,2,1);
x1 = linspace(0,6);
y1 = sin(x1);

ax2 = subplot(2,2,2);
x2 = linspace(0,10);
y2 = sin(2*x2);

ax3 = subplot(2,2,[3,4]);
x3 = linspace(0,16);
y3 = sin(6*x3);


To remove the linking, use linkaxes([ax1,ax2,ax3],'off').

Load the count.dat data set which returns a three-column array named count. Create a new figure with three subplots and return the axes handles. In each subplot, create a bar graph.

load count.dat  

ax1 = subplot(3,1,1);

ax2 = subplot(3,1,2);

ax3 = subplot(3,1,3);

Link the x-axes and y-axes limits using linkaxes with the argument 'xy'. Base the limits on the third subplot by passing its axes handle, ax3, as the first input to linkaxes.


If you zoom in on one subplot, then the other two subplots behave in the same manner. To enable interactive zooming, use zoom on. To disable zooming, use zoom off.

Load the count.dat data set which returns a three-column array named count. Create a new figure with two subplots and return the axes handles. In each subplot, create a bar graph.

load count.dat
ax1 = subplot(2,1,1);

ax2 = subplot(2,1,2);

Link the x-axes for the two subplots.


Set the x-axis limits for the second subplot. Setting the limits overrides the limits initially set by linkaxes. Changing the x-axis limits effects both subplots.

ax2.XLim = [4.5,9.5];

If you pan either subplot, then both subplots pan uniformly in the x-direction, but only one subplot moves in the y-direction. To enable interactive panning, use pan on. To disable panning, use pan off.


The first axes you supply to linkaxes determines the x- and y-limits for all linked axes. This can cause plots to partly or entirely disappear if their limits or scaling are very different. To override this behavior, after calling linkaxes, specify the limits of the axes that you want to control with the set command, as the third example illustrates.

    Note:   linkaxes is not designed to be transitive across multiple invocations. If you have three axes, ax1, ax2, and ax3 and want to link them together, call linkaxes with [ax1, ax2, ax3] as the first argument. Linking ax1 to ax2, then ax2 to ax3, "unbinds" the ax1-ax2 linkage.

See Also

| | |

Introduced before R2006a

Was this topic helpful?