Documentation

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.

linkaxes

Synchronize limits of specified 2-D axes

Syntax

linkaxes(ax)
linkaxes(ax,option)

Description

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:

'x'

Link x-axis only.

'y'

Link y-axis only.

'xy'

Link x-axis and y-axis.

'off'

Remove linking.

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

Examples

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.

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

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

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

linkaxes([ax1,ax2,ax3],'xy')

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);
bar(count(:,1),'g');

ax2 = subplot(3,1,2);
bar(count(:,2),'b');

ax3 = subplot(3,1,3);
bar(count(:,3),'m');

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

linkaxes([ax3,ax2,ax1],'xy'); 

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
figure
ax1 = subplot(2,1,1);
bar(count(:,1),'g');     

ax2 = subplot(2,1,2);
bar(count(:,2),'b');

linkaxes([ax1,ax2],'x');

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.

Tips

  • 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

Was this topic helpful?