scaleline¶
- scaleline(varargin)
SCALELINE Add a scale bar (with label) to an x- or y-axis; scales with zoom
- Usage:
[h_scaleline, h_scalelabel] = scaleline(ax, time) [h_scaleline, h_scalelabel] = scaleline(ax, time, label) [h_scaleline, h_scalelabel] = scaleline(ax, time, label, line_axis) [h_scaleline, h_scalelabel] = scaleline(ax, time, label, line_axis, gap)
- Inputs:
ax : axes handle (default: gca) time : double - scale length in plot units – required label : char - label text (default: ‘<time> units’) line_axis : ‘x’ or ‘y’ - which axis the bar attaches to (default: ‘x’) gap : double - gap between bar and axis in normalized figure
units (default: 0.01; 3-D: bar and label sit 1x and 3.5x gap outside the box, measured on screen)
- Outputs:
- h_scalelinehandle for the scale bar (annotation line in 2-D;
line object in the axes in 3-D)
- h_scalelabelhandle for the label (annotation textbox in 2-D;
text object in the axes in 3-D)
Notes
2-D: the label textbox is measured once with FitBoxToText and then frozen, so it can be positioned by its known size. Positioning an anchored zero-size box with FitBoxToText left on is not stable across MATLAB versions: the fit’s growth direction follows the alignment properties in newer releases (a bottom-aligned box grows upward from its anchor), where older releases grew the box downward. Measuring requires one drawnow at creation.
3-D (detected from the axes View): annotation space cannot express a bar along a projected axis edge, so the bar and label are drawn in DATA coordinates, tracking the front bottom edge of the box – the same edge MATLAB draws the ruler on, chosen from the camera azimuth/elevation. Analogous to the 2-D bar, it sits at the end of the ruler that projects to the upper-left on screen, offset perpendicular to the projected ruler just outside the box, with the label further out and rotated parallel to the bar. The bar length is exact in data units from any view. Limit and View listeners keep everything in place through zoom and rotation.
Example
surf(peaks(50)); scaleline(gca, 10, ‘10 units’);
See also: annotation, line, text, stacked_plot
∿∿∿ Prerau Laboratory MATLAB Codebase · sleepEEG.org ∿∿∿