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.
Allen (2019). DragDataTip (https://www.mathworks.com/matlabcentral/fileexchange/69799-dragdatatip), MATLAB Central File Exchange. Retrieved .
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
-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.
Create scripts with code, output, and formatted text in a single executable document.