File Exchange

image thumbnail


version 3.2 (5.92 KB) by Allen
Creates draggable data tips with custom labeling options on 2-D plots. Custom labels also work on default MATLAB Data Tips.


Updated 03 Jun 2019

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This function provides a solution to the limited positions allowed by standard MATLAB Data Tips on
2-D plots by replacing them with draggable versions when the plot's "Data Tips" mode is toggled
'off'. Since MATLAB Data Tips only allow the user to move the data tip to a position where one of
its four corners touches the data point, this can often obstruct portions of nearby graphed data.
Draggable data tips can be moved anywhere on the current axes, thus allowing better visibility of
the plot. Draggable data tips use a connecting line between the data tip textbox and its original
corresponding data point. They also utilize a textbox border with the same line properties as the
target line object. Both features help to provide a smooth visual reference between the plot data
and the data tips.

This function also allows the user to provide custom X- and Y-value labels to replace the default
'X' and 'Y' with something more descriptive (i.e. - 'Time' and 'Accel'), as well as adding a
header label to the data tip textbox. This is accomplished by using the varargin input. Headers
add text above the X- and Y-value labels that match the line object's display name as shown in the
legend. While the data tip header feature requires a legend to exist on the target plot axes at
the time that the data tip is created, the legend can be deleted after creating the data tip
without changing its header value. If a legend does not exist when the data tip is created, the
header option's default 'off' value is used.

Even though the optional labels are applied to all axes on a single figure, it is still possible
to use different labels for multiple axes on a single plot. This is done by reapplying the
function with a new set of labels before adding new data tips to separate axes.

An EXAMPLE section is provided in the function notes for how to properly use this function. If you
have questions or trouble using this function, leave a comment below.

Please rate it if have a chance; all feedback is welcome.
Thanks and enjoy, but don't forget to also download Francois Bouffard's draggable.m function.

Cite As

Allen (2019). DragDataTip (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)


bcplay, thank you for pointing that out. I had recently discovered that it does not work with 'duration' data types as well as 'date/time'. It appears to be related to performing power and root calculations to these types of data. I will look into a solution for this issue and will post a fix as soon as I can. -Thanks


Doesn't seem to work when x-axis values are dates

Andre Zeug



- Fixed bug to apply function to multiple figures simultaneously.
- Fixed bug to work with 'duration' data types
- Added non-draggable display fixes for 'date/times'. Requires update to draggable.m to make 'date/times' draggable.


-Added 'on/off' option to the draggable feature. Allows header and labels to be applied to standard data tips.


- Now works with a single line of code.
- Assigns function to the current figure when the 'hFig' input is not used.
- Improved data tip deletion methods.
- Fixed bug that allowed data tips to be applied to existing data tip leader lines.


- Changed function behavior to utilize a property listener on the DataCursorManager "Enable" property. This allows toggling of the DataCursorMode between 'on' and 'off' to create the draggable data tips vs the previous need to use the "KeyPressFcn".


- Updated parsing of varargin.
- Fixed bug when applying custom data tip labels to default MATLAB Data Tips.


- Apply custom data tip labels to default MATLAB Data Tips before creating draggable versions.
- Fixed bug that prevented default (gca) assignment of hAx input when not provided.


Added Acknowledgements

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

Inspired by: draggable, Draggable data tips

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor