This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country 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 the linked 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. Use linkaxes for Cartesian axes in 2-D views only.

linkaxes(ax) links the x- and y-axis limits of the Axes objects specified in the vector ax. The linkaxes function chooses limits that incorporate the current limits for all the linked axes.

linkaxes(ax,option) links the axes 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. 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 figure with three subplots and return the Axes objects. 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'. 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 figure with two subplots and return the Axes objects. In each subplot, create a bar graph. Link the x-axes for the two subplots.

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

ax2 = subplot(2,1,2);


Set the x-axis limits for the second subplot. 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.


  • 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 and then ax2 to ax3 with separate calls to linkaxes, "unbinds" the ax1-ax2 linkage. linkaxes is not designed to be transitive across multiple invocations.

See Also

| | |

Introduced before R2006a