File Exchange

image thumbnail


version 4.0 (7.81 KB) by Allen
Creates draggable data tips with custom labeling options on most 2-D plots. Custom labels options can also be applied to standard data tips.


Updated 12 Aug 2019

View Version History

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
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.

Cite As

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

Comments and Ratings (16)


Unfortunately I am unable to duplicate the same problem. It is possible that it might have to do with the computer platform, OS version, or MATLAB version that you are using. I may not be able to do much to vet this on difference systems,, but if you are able to share that information, I will give it a try.

Christian Wimmer

Hi Allan, thank you for your super fast response.
I tried what you said but did not get the results that I expected. This is what I actually do:

close all
hold on

When I move the mouse around in the graph I see the data tips and when I click I see them in blue and they are attached to the line. Unfortunately I see just the "x" and "y" numbers but not to which line they belong (plot1 or plot2).
I can zoom in and out and pan and all works nice just that I do not see the DisplayName.

When I now use your program


then the DataTips doe not change until I click on "DataTip" button. After this the Datatips appear as I want them. They are moveable and contain the plot1 or plot2 information. Just that now it is not possible any more to zoom in or out even if I click again the "DataTip" button.

What can this be?

Could you give me one more hint of what I can try?



It sounds like you may need to click the Datatip "button" after adding your DataTips to your axes. MATLAB only allows for use of one of the axes at a given time. Let me know if you are still running into problems after verifying you are performing the following steps.
1. Enable datatips (use the axes toolbar button in the upper-right). Icon turns blue.
2. Add datatips
3. Disable datatips (again use the toolbar button in the upper-right). Icon turns gray.
This function waits for the datatip function to disabled after adding datatips before converting them to the draggable versions. Thanks for the feedback and look forward to your response.

Christian Wimmer

Hi Allen, I just downloaded your program and run into the same problem as Patricia with Matlab R2019a. After clicking the Datatip "button" in the upper right corner it started working. Unfortunately it does not stop any more. What ever I do a after this I can not zoom pan any more the page. Could you have a look please? The snippet of code is as simple as


Thanks in advance!


I appreciate you providing me with a snippet of the code you are working with. I have not had much time lately to look into addressing your issue, but will eventually do so.

Patricia Darling

Hi Allen, I'm trying to get this to work but not sure if I'm missing something. I'm using Matlab 2020a, and I ran the sample you have in the function header, then click on the plot to add a datatip, and attempt to drag it, and it performs just as it normally does, not moving. Am I missing something else I should be doing? Thanks!


Hi Allen, I'm working with simple numeric data. Consider the following example: `X = (-5:5).'; Y = rand(11,1); figure(); hP = plot(X,Y); hT = hP.DataTipTemplate; hT.DataTipRows(1:3) = [dataTipTextRow('Foo', abs(X)), dataTipTextRow('Bar', X.^2), hT.DataTipRows(2)]; hT.DataTipRows(end).Label = "Baz";` <- Then apply DragDataTip to this chart and compare the datatips before and after conversion to draggable. As a matter of fact, I've implemented a fix for this already. If you link your submission to e.g. GitHub, I'd be happy to discuss this in depth with code snippets and rendered outputs (and could also submit a PR).


Dev-iL, thank you for your comment. I have not yet had the opportunity to work with the new 'dataTipTextRow' and 'DataTipTemplate' features, but will gladly look into providing a fix to the issue you are experiencing. Until then, could you provide me with a sample of the code you are using and indicate what data type(s) you may be working with?


Thank you Allen for this useful submission! I have one issue with it though: I'm creating multi-row datatip labels with the new functionality of `dataTipTextRow` and `DataTipTemplate` introduced in R2019a (my datatips have 4 rows which include the YData and some other information depending on the XData). Upon conversion of the built-in datatips to draggable ones, this information gets lost, and I'm left with just X and Y information (which I don't need). Is there anything that you can do so that the code respects the existing `DataTipTemplate`?


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!

Andrew Netherton

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

Andre Zeug

Chang hsiung

Chang hsiung

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

Inspired by: draggable, Draggable data tips

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!