This function provides a solution to the limited positions allowed by standard MATLAB Data Tips on
most 2-D plots by replacing them with draggable versions when the plot's "Data Tips" mode is
toggled 'off'. Since standard data tips can only be moved to a position where one of its four
corners touches the chosen data point, this often obstructs portions of nearby graphed data.
Draggable data tips can be moved anywhere on the current axes, thus allowing better visibility of
the plot. Several visual features are used to reference the draggable data tip to its data point
and parent object. These include a connecting line between the data tip textbox and its
corresponding data point, and the data tip border will try to utilize the same line properties as
the target line object.
The varargin input argument allows the user to optionally customize the data tips labels. For
example X- and Y-value labels can be replace with something more descriptive such as 'Time' and
'Accel'. In addition to axis labels and when a plot legend is used, a header label can be added to
the data tip. Headers are added above the axis labels and match the target object's display name
as it appears in the legend. While the data tip header feature requires a legend to exist prior to
creation of the data tip, the legend can be deleted after creating the data tip and will not
effect the header label. If a legend does not exist when the data tip is created, the header
option is ignored.
Note that optional labels are applied to all axes on a single figure. However, 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 creating additional data tips containing the new
An EXAMPLE section is provided in the function notes, but 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.
Allen (2019). DragDataTip (https://www.mathworks.com/matlabcentral/fileexchange/69799-dragdatatip), MATLAB Central File Exchange. Retrieved .
Andrew, thank you for your feedback. While originally intended for plot(), loglog(), and semilog plots, version 4.0 addresses some issue associated with various other 2-D plot types including scatter(). Additionally, several other overall improvements have been made. Give the new version a run and let me know if you run into any other problems. -Thanks!
I would warn that this function doesn't seem to work universally with all available 2D plotting functions. Some warnings were generated when I attempted use the draggable data tips with a scatter() plot, but it's easy enough to phrase a plot() operation to look like the output of a scatter() operation.
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
- Incorporate draggable() directly into code to address multiple issues
- Fixed bug to apply function to multiple figures simultaneously.
-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.
- 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.
- Apply custom data tip labels to default MATLAB Data Tips before creating draggable versions.