How to move data tip in R2025b? (Or, how to restore legacy data tip behavior)

In previous versions of matlab, an existing data tip would move to a new point whenever I clicked on a new point in a graph or image, and I could also use the arrows on the keyboard to move the data tip one pixel at a time. In R2025b I get a new data tip each time I click somewhere in a plot, and there does not seem to be any way to move the data tips to a different point. How can I make the data tips behave like they did before? I never want to have hundreds of data tips in a plot, so holding shift while clicking in order to create a second data tip is not a problem.

 Accepted Answer

Another option is to supply your own datatip, with an UpdateFcn defined by you:
function datatipDemo()
% Minimal example that restores "single movable data tip" behavior
% in MATLAB R2025b by simply assigning a custom UpdateFcn.
% Make a demo image
I = peaks(200);
imagesc(I); axis image; colormap parula
title('Click anywhere; arrow keys move the data tip')
% --- KEY: Use datacursormode and set a custom UpdateFcn ---
hdt = datacursormode(gcf);
hdt.UpdateFcn = @myUpdateFcn;
datacursormode on;
end
function out = myUpdateFcn(~, evt)
% Very simple update function. No indexing, overlays, etc.
pos = evt.Position;
val = evt.Target.CData(round(pos(2)), round(pos(1)));
out = {
sprintf('x = %d', round(pos(1)))
sprintf('y = %d', round(pos(2)))
sprintf('value = %.3f', val)
};
end

4 Comments

I tested it now and after a small modification, I got it to work for both plots and images. Is there any way I can make this function the default data tip function for all figures or do I need to set the custom data tip function for each figure?
I got it to work for both plots and images.
I'm glad you got it to work, but if so, kindly Accept-click the answer.
Is there any way I can make this function the default data tip function for all figures
Yes, you can set the defaultAxesCreateFcn like below. Then the change will apply to every new figure you create unitl you close Matlab. If you put this in your startup.m file, the behavior will also re-assert every time you launch a fresh Matlab session.
NOTE: You must use the defaultAxesCreateFcn, not the defaultFigureCreateFcn.
if ~isMATLABReleaseOlderThan("R2025a")
set(groot,'defaultAxesCreateFcn',@(ax, ~)AxCreate2025(ax));
end
function AxCreate2025(ax)
fig=ancestor(ax,"Figure");
hdt = datacursormode(fig);
hdt.UpdateFcn = @myUpdateFcn;
datacursormode on;
datacursormode off;
end
function out = myUpdateFcn(~, event)
% Very simple update function.
fig = ancestor(event.Target, 'figure');
switch event.Target.Type
case 'image'
case 'line'
datacursormode(fig,'on');
end
% Display the new data cursor information
out = {['X: ', num2str(event.Position(1))], ...
['Y: ', num2str(event.Position(2))]};
end
You can edit startup.m to change the figure creation function to do this every time a new figure is created.
@Rik No, unfortunately the figure creation function will not work because it gets run before the axes is created, meaning that all the datacursor settings get overwritten later once the axes is created. You must use the defaultAxesCreateFcn instead.

Sign in to comment.

More Answers (2)

You can activate the old-style figure toolbar exploration buttons, e.g.,
addToolbarExplorationButtons(gcf)
That seems to have the old datacursor behavior.

8 Comments

I do that sometimes, but since Win 11 does not have a taskbar that works when you open more than a few windows, I sometimes need to use the new figure window in order to be able to see all my figures at the same time (as opposed to having the tabs hidden in the "fantastic" new overflow menu that Microsoft has bestowed upon us in Win 11).
I haven't really seen any taskbar problems in WIn 11, nor do I really see how that encumbers the solution I proposed. The solution doesn't really require you to open more figure windows than you did originally.
I guess it wasn't obvious from what I wrote, but the problem is simply that when I open a sufficient number of figures (typically somewhere between 8 and 12, but can be as few as 4 if I have many other applications open), Windows 11 insists on combining all the figures under a single Matlab tab. This means that each time I want to switch from one figure to another, I need to first hover over the matlab tab and then potentially scroll up or down in a list before I can click on the figure I want to see. That is very inefficient, so when I need to open many figures at the same time, I sometimes prefer to use the new figure browser setup that came with matlab 2025, since there I can switch between the figures without using the taskbar. The new figure browser is however not compatible with the old toolbar menu, so I cannot use that trick to make the data tips work like before there.
Windows 11 insists on combining all the figures under a single Matlab tab.
That's not new in Windows 11. In the Taskbar Settings, you can turn that off:
Unfortunately, that setting does not work as it should in Win 11 (at least not in the version I'm using). The never combine setting hides even more items in the overflow menu and leaves half the taskbar empty, so it's even worse than the combine only when full setting (see attached screenshot showing that Matlab, Teams and settings are all hidden in the overflow menu when I use the never combine setting). This bug in the taskbar behaviour is obviously not Matlab's fault, but it does nonetheless have an effect on how I use Matlab when working with many figures open at the same time.
Strange. Well, it definitely shouldn't do that (and doesn't for other people), so you might want to look into it.
It does this for other people as well, but you're less likely to experience it if you have a wide screen instead of a dual monitor setup with smaller screens. If you have a wide screen, you may be able to open 30-40 windows before the bug occurs, whereas for me it happens when I get to somewhere around 15-20 open windows. (Here's just one of several examples of other people with the same experience as me: https://learn.microsoft.com/en-us/answers/questions/1481864/windows-11-taskbar-width)
OK, I think I managed to reprdouce it. In any case, did you try my other answer? It restores the old datatip behavior entirely.

Sign in to comment.

there does not seem to be any way to move the data tips to a different point
Hold the shift key down while you press the arrow keys.

5 Comments

Thanks, that seems to work for images and within curves. Is there also a way to move the data tip from one curve to another, or is the only solution to create a new data tip and delete the old one? (I sometimes need to look at a lot of curves that are almost on top of each other, so having multiple data tips at the same time is not always a viable option.)
I don't think that's possible. It looks quite intentional in the design that you cannot jump the data tip to another curve. Otherwise, if you did want to step along a single fixed curve, you would end up doing a lot of gymnastics with the arrow keys, depending on the shape of the curve.
In previous versions of Matlab, you could move the data tip to a different curve by clicking, so I find it puzzling that they have removed this functionality. But since Matt provided a way to bring back the previous behaviour for data tips, I now have a solution for that.
In previous versions of Matlab, you could move the data tip to a different curve by clicking,
By clicking perhaps, but with the arrow keys?
Also possibly useful -- I find in R2025b that when you hold down the shift key, any data tip you place will self-delete once the mouse button is released. This works both in images and line plots.
It doesn't give you the exact same experience as before, but it does provide a way to probe multiple points without the plot getting cluttered with data tips, and without the extra key strokes needed to explicitly delete data tips.

Sign in to comment.

Categories

Products

Release

R2025b

Community Treasure Hunt

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

Start Hunting!