| MATLAB Function Reference | ![]() |
linkaxes(axes_handles)
linkaxes(axes_handles,'option')
Use linkaxes to synchronize the individual axis limits across several figures or subplots within a figure. Calling linkaxes will make all input axes have identical limits. Linking axes is most useful when you want to zoom or pan in one subplot and display the same range of data in another subplot.
linkaxes(axes_handles) links the x- and y-axis limits of the axes specified in the vector axes_handles. You can link any number of existing plots or subplots.
linkaxes(axes_handles,'option') links the axes' axes_handles according to the specified option. The option argument can be one of the following strings:
| 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 linking object properties on any graphics object.
The first axes provided to linkaxes determines the x-limits and y-limits for all axes linked. 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 wish to control with the set command, as shown in Example 3, below.
You can use interactive zooming or panning (selected from the figure toolbar) to see the effect of axes linking. For example, pan in one graph and notice how the x-axis also changes in the other. The axes will respond in the same way to zoom and pan directives typed in the Command Window.
This example creates two subplots and links the x-axis limits of the two axes:
ax(1) = subplot(2,2,1); plot(rand(1,10)*10,'Parent',ax(1)); ax(2) = subplot(2,2,2); plot(rand(1,10)*100,'Parent',ax(2)); linkaxes(ax,'x');
This example creates two figures and links the x-axis limits of the two axes. The illustration shows the effect of manually panning the top subplot:
load count.dat figure; ax(1) = subplot(2,1,1); h(1) = bar(ax(1),count(:,1),'g'); ax(2) = subplot(2,1,2); h(2) = bar(ax(2),count(:,2),'b'); linkaxes(ax,'x');
Choose the Pan tool (Tools > Pan) and drag the top axes. Both axes will pan in step in x, but only the top one pans in y.

Create two subplots containing data having different ranges. The first axes handle passed to linkaxes determines the data range for all other linked axes. In this example, calling set for the lower axes overrides the x-limits established by the call to linkaxes:
a1 = subplot(2,1,1);
plot(randn(10,1)); % Plot 10 numbers on top
a2 = subplot(2,1,2);
plot(a2,randn(100,1)) % Plot 100 numbers below
linkaxes([a1 a2], 'x'); % Link the axes; subplot 2 now out of range
set(a2,'xlimmode','auto'); % Now both axes run from 1-100 in x
% You could also set(a2,'xlim',[1 100])

![]() | LineSpec | linkdata | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |