This function allows for the creation of draggable data tips when using 2-D plots by replacing
default MATLAB Data Tips currently on a plot axes. Since default MATLAB Data Tips stack on top of
existing plot data and only allow the user to move the data tip to a position where one of its four
corners touches the data point, this often times blocks segments of nearby data. Draggable
data tips allow the user to move it anywhere on the current axes, thus allowing better visibility
of important data. Reference to its original data point is maintained by adding a connecting line
between the data tip textbox to its corresponding data point.
Additionally, this function 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 a data
tip header. When the header feature is turned on and a legend exists on the target plot axes, a
text string is added above the X- and Y-value labels that matches the object display name(s) as
listed within the legend. This feature requires that a legend must first be added to the axes
before the draggable data tips are created, but does not rely on the legend remaining on the axes
after the data tips have been created.
In order to use this function, it must be assigned to @KeyPressFcn property for a figure. After
using the default MATLAB data cursor tool to place tips on a plot, turn off the Data Cursor Tool
and press 'Ctrl+M' to replace all default Data Tips currently on the specified axes with draggable
versions. The draggable data tips can be removed by pressing the 'delete' key.
To update the default MATLAB data tips with custom labels, this function must be applied to the
@UpdateFcn property of the DataCursorManager handle.
An EXAMPLE section is provided in the function notes for how to properly use this function. If you have questions or trouble implementing this function, please 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 .
- Updated parsing of varargin.
- Apply custom data tip labels to default MATLAB Data Tips before creating draggable versions.
Create scripts with code, output, and formatted text in a single executable document.