labelpoints
Editor's Note: This file was selected as MATLAB Central Pick of the Week
[Major update with additional features coming soon; don't forget to follow this file.]
Given vectors of x-values, y-values, and a vector of label names, lablepoints.m will automatically place all labels appropriately in the plot and output their handles. This function streamlines matlab's builtin text() function and greatly increases its flexibility.
.
xpos = [1,2,3,4]; ypos = [1,4,1,5]; labels = {'Lancaster', 'Cincinnati', 'Sofia', 'Rochester'}
h = labelpoints (xpos, ypos, labels)
.
(optional) Choose where you want your label relative to the data point using initials of compass directions (N, S, E, W, NE, NW, SE, SW, Center).
h = labelpoints (xpos, ypos, labels, 'N')
.
(optional) Add (or subtract) extra space between data points and labels by using a buffer between 0:1
h = labelpoints (xpos, ypos, labels, 'N', 0.15)
.
(optional) Decide whether or not the axis limits should automatically adjust if a label falls out of the axis limits (0/1)
h = labelpoints (xpos, ypos, labels, 'N', 0.15, 1)
.
(optional) Let labelpoints.m identify and label only the outliers in your data. Several outlier methods are available (see help labelpoints)
- Identify and label outliers that are N standard deviations from the mean
- Identify and label outliers that are greater than N times the interquartile range
- Identify and label outliers that are inside or outside of a given bound
- Identify and label outliers that are high residuals from a linear fit of the data.
.
(optional) Easily place texts in a list stacked downward, upward, to the left or right.
h = labelpoints (xpos, ypos, labels, 'N, 'stacked', 'down')
.
(optional) Rotate all labels
h = labelpoints (xpos, ypos, labels, 'rotation', 45)
.
(optional) Specify the font size and color of all labels
h = labelpoints (xpos, ypos, labels, 'FontSize', 12, 'Color', 'r')
.
The help section includes many versatile examples demonstrating labeling with numbers, strings, and symbols. This function is quite flexible as the examples show. There are only three required inputs, 3 optional inputs, and several optional parameters to increase flexibility. The outlier options may require stats toolbox.
Cite As
Adam Danz (2024). labelpoints (https://www.mathworks.com/matlabcentral/fileexchange/46891-labelpoints), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Graphics > Formatting and Annotation > Labels and Annotations >
- MATLAB > Graphics > Formatting and Annotation > Labels and Annotations > Axis Labels >
Tags
Acknowledgements
Inspired by: vdpdemo
Inspired: hist3d(x,y,w,varargin), Getting Started with Portfolio Optimization (Files for Video Demo)
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
4.1.1 | 'Major update coming' announcement added to the description; no changes made the file. |
|
|
4.1 | Replaced use of isdatetime() with isa() so older versions of matlab won't cause error. |
|
|
4.0.0.0 | fixed typos.
|
||
3.0.0.0 | All changes listed within labelpoints.m under 'change history' starting after 11/15/14.
|
||
1.4.0.0 | Improved the 'outliers_N' optional parameter and added the automatic removal of points that have 'inf' value.
|
||
1.3.0.0 | There was an error within the optional text rotation parameter.
|
||
1.2.0.0 | This function has added several features onto the first version but has not affected functionality of earlier versions. |
||
1.1.0.0 | Added an additional example in the help file. No changes to code. |
||
1.0.0.0 |