File Exchange

image thumbnail

Scale bar for 2D axes

version 1.1.0.0 (9.86 KB) by Amanda
Creates a scale bar in a 2D axes. The length, location and colour of the scale bar are customisable.

4 Downloads

Updated 24 Mar 2014

View Version History

View License

SCALEBAR creates a scalebar on an axes

SCALEBAR
SCALEBAR OFF
SCALEBAR(PARAMETER, VALUE, ...)
SCALEBAR(HAXES, PARAMETER, VALUE, ...)
H = SCALEBAR(...)

Draws a scalebar on the axes and returns handle to the scalebar. The DataAspectRatio property of the axes must be set to [1 1 1] and the view must be in 2D. All parameters are optional (note the default values below). SCALEBAR OFF deletes the current scalebar.

PARAMETER/VALUE pairs
hAxes: handle to the axes (defaults to current axes)
ScaleLength: length to show (in data units) (defaults to ~10% of the x-axis limit range)
ScaleLengthRatio: ScaleLength/range(XLim)
Location: location of the scalebar. Possible values are
northeast (default)
northwest
southeast
southwest
[x y] data coordinates
Colour: colour of scalebar in 1x3 RGB array (default is [0 0 0])
Bold: draw with bold text and linewidth=2. True or false(default)
Unit: string containing units e.g. 'mm'

Cite As

Amanda (2020). Scale bar for 2D axes (https://www.mathworks.com/matlabcentral/fileexchange/25799-scale-bar-for-2d-axes), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

Jashan Chopra

Drew Marquis

Works as described. I've found that this works best if you use "axis equal" before you call the function

Ulrich Mouaffo

Muhammad Usman Saleem

Shenlei Zhu

Can you add a function that I can modify the number of scale bar? Sometimes, the number of your scale bar show is not correct and the actual value should be another value, therefore I could edit the scale bar and make it more accurate.

Shenlei Zhu

I mean that the number of your scale bar shows sometimes is not in the same coordinates.

Sebastien Blaise

Works well.

It depends on the function "range" which requires the appropriate toolbox.

As range is a very simple function, it would be useful to remove this dependency, such that everyone can use it directly.

Anita

Amir

I get a "Undefined function 'range' for input arguments of type 'double'." error

Tiago Ferreira

The fact that this function depends on a data aspect ratio of [1,1,1] makes its applications quite limited for actual presentation of signals.

Pierce

Hi, thanks for the very useful code. Is there a way to get the scalebar in the foreground? Currently my surf overlaps the scalebar.

Thanks

Amanda

Hi Max,

Very sorry for the much belated response. I've incorporated your suggestion into the code and it now has the option for a unit string.

Regards,
Amanda

Max Rose

Thank you for this useful function!

However it would be nice to input or assign a physical unit in order to clarify what physical quantity the scalebar refers to.

Do you think it would be possible to add a physical unit as a string parameter to the scalebar.m function?

Cheers!

Useful and simple! Thanks very much

MATLAB Release Compatibility
Created with R2008b
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!