Align Axes Limits

版本 1.0.0 (4.8 KB) 作者: Todd Baxter
Align and link axis limits of Cartesian axes
2.0 次下载
更新时间 2023/6/11

查看许可证

Usage:
alignaxeslimits(H, AXIS, METHOD)
alignaxeslimits(H, AXIS, METHOD, AXIS, METHOD, ...)
Inputs:
H <array of axes or figure handles>
- Handles to the axes, or figures containing axes, to align and link
- Must contain 2 or more handles
- If figure handles are input, then every figure must have the same
number of axes and the corresponding axes across all of the figures
will be aligned and linked
AXIS <character array or scalar string>
- Axis limits to align and link
- Specified as any combination of the letters 'x', 'y', and 'z' only
METHOD <character array, scalar string, or scalar axes or figure handle>
- Method to use for alignment of the axis limits
- Character array or scalar string
* 'max' - Sets the axis limits to the union of the current axis limits
* 'min' - Sets the axis limits to the intersection of the current
axis limits. Note, if there is no overlap between the
axis limits, then an error will be thrown.
* 'off' - Removes the linking of the axis limits, but will not undo
the alignment of the axis limits
- Scalar axes handle
* Sets the axis limits to the current axis limits of this axes
* Must have specified an array of axes handles to align
- Scalar figure handle
* Sets the axis limits according to the current axis limits of the
axes contained in this figure
* Must have specified an array of figure handles to align
* Must contain the same number of axes as the other figures
Description:
Each axes will maintain a reference to the linkprop object(s) created
to link the axis limits. That way the linking of the axis limits will
remain active even if some of the axes are deleted. Although, this
means that if it is desired to turn the linking 'off', then all of the
handles passed to the original aligning and linking call will have to
be passed to the turn linking 'off' call.
Examples:
fig1 = figure;
ax1(1) = subplot(2, 1, 1, 'Parent', fig1);
ax1(2) = subplot(2, 1, 2, 'Parent', fig1);
t1 = linspace(0, 4*pi, 100);
t2 = linspace(pi, 3*pi, 100);
plot(ax1(1), t1, 1 + sin(t1));
plot(ax1(2), t2, -1 + cos(t2));
% Align and link the x-axis limits (to their intersection)
alignaxeslimits(ax1, 'x', 'min');
fig2 = figure;
ax2(1) = subplot(2, 1, 1, 'Parent', fig2);
ax2(2) = subplot(2, 1, 2, 'Parent', fig2);
plot(ax2(1), t1, 2 + sin(t1));
plot(ax2(2), t2, -2 + cos(t2));
% Now align and link the x-axis and y-axis limits of the second figure
% to the first figure
alignaxeslimits([fig1,fig2], 'x', fig1, 'y', 'max');
% If it is desired to have all x-axis limits linked, then axes handles
% can be passed. Note, the alignment method does not matter in this
% case since the x-axis limits were already aligned above.
alignaxeslimits([ax1,ax2], 'x', ax1(1));

引用格式

Todd Baxter (2024). Align Axes Limits (https://www.mathworks.com/matlabcentral/fileexchange/130899-align-axes-limits), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2022a
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0