Scalebar for images and plots

Create a customizable scalebar for x- and/or y-axis of a 2D plot.
Updated 30 Nov 2022

View License

Create a scalebar object for x- and or y-axis. Scalebar appearance is configured on creation, through setting of properties, or interactively using a context menu.
Note: For precise positioning, plotboxpos is required.
  • Option to autoadjust scalebar on zoom.
  • Scalebar stays in place on zooming and panning
  • Update scalebar size and appearance interactively from contextmenu
  • Save scalebar appearance to preferences, so next scalebar created will use same appearance.
f = figure();
hAx = axes(f);
imshow('cell.tif', 'Parent', hAx);
pixPerUm = 5;
scalebarLength = 10; % scalebar will be 10 micrometer long
unit = sprintf('%sm', '\mu'); % micrometer
hScalebar = scalebar(hAx, 'x', scalebarLength, unit, 'Location', 'southeast', ...
'ConversionFactor', pixPerUm);
Known Bugs
Scalebar position is not correctly updated when interactive zooming tools are activated and user doubleclicks in axes

Cite As

Eivind Hennestad (2024). Scalebar for images and plots (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

Update image


Fix potential infinite recursive callback loop


Changed file


Adds to current axes if parent is not specified
Fixed bugs when updating position in axes where hold is 'off'
Updated doc


Updated image