| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
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 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.
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. The axes_handles input should be a vector of the handles for each plot or subplot. Entering an array of values results in an error message.
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 you to link object properties on any graphics object.
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 shown in Example 3.
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. |
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 responds in the same way to zoom and pan directives you type 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 pans 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 use set(a2,'xlim',[1 100])

![]() | LineSpec (Line Specification) | linkdata | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |