How to enable data tips?

Hi guys, i have a problem with enabling data tips in matlab R2019b.
Im using app designer and would like to add data tips to the UIAxes.
I try using:
datacursormode(app.Bitmap);
where app.Bitmap is the UIXes name, but it gives me an error saying
"Error using datacursormode (line 154)
Invalid figure handle"
So i have no idea what to do now and Id prefer not to make a figure outside GUI.
Thanks in advance

Answers (1)

Adam Danz
Adam Danz on 16 Nov 2019
Edited: Adam Danz on 18 Feb 2020
The optional input to datacursormode() is a figure handle, not an axis handle. Data cursor mode has only recently been supported in app designer axes and it's 'on' by default. The datacursormode() does not have an effect on app designer figures, though (r2019b, according to my test)
What release of Matlab are you using?
Also see

10 Comments

im using r2019b if thats what you are asking
In r2019b data cursor mode should be on by default.
Try running enableDefaultInteractivity(app.UIAxes) (although I'm not sure if that is supported by UIAxes yet).
If that doesn't work, you could attach your mlapp file so we can poke around.
Nick Bennett
Nick Bennett on 15 Oct 2020
Edited: Nick Bennett on 15 Oct 2020
Hello,
When working with appdesigner in Matlab 2020a, I am not seeing any data cursor enabled for axes in my user interface. Here I have circled where I was expecting to see the data cursor icon when hovering mouse over the axes.
When working in GUIDE, this functionality was automatically enabled. Here is an example for one my my GUIDE applications.
I sense from the earlier post that data cursor functionality should be enabled by default?
Also, would this issue be related to my not being able to right-click and open a Context Menu? I am also seeing this issue.
Suggestions?
What's plotted (what plotting function was used)?
Thanks for this question, Adam.
Actually I do have the first application both in GUIDE and appdesigner, and the one from GUIDE does have the datacursor. Here is a screenshot of the version in GUIDE running from the MATLAB command line.
This application creates the UI display using imagesc to create the background image from a 2D array (rho, for density), then I use plot to overlay a few additional curves. Here is the basic code I am using from appdesigner. It is a pretty close translation of the implementation in GUIDE.
imagesc(app.ViewPanel, coordinates.x, coordinates.z, rho');
hold(app.ViewPanel, 'on');
plot(app.ViewPanel, app.loc_data.xTraj_eqSpaced_m, app.loc_data.zTraj_eqSpaced_m, '-c', 'Linewidth',2)
plot(app.ViewPanel, app.loc_data.xTraj_eqSpaced_m([selIndx1 selIndx2]), app.loc_data.zTraj_eqSpaced_m([selIndx1 selIndx2]), 'ks', 'MarkerfaceColor','k','MarkerSize',10)
hold(app.ViewPanel, 'off');
hold(app.ViewPanel, 'on');
for indx = 1:25:length(app.loc_data.xTraj_eqSpaced_m)
text(app.ViewPanel, app.loc_data.xTraj_eqSpaced_m(indx), app.loc_data.zTraj_eqSpaced_m(indx),...
num2str(indx), 'Color', 'w');
end
hold(app.ViewPanel, 'off');
title(app.ViewPanel, [ 'Layered Model // Property: ' str_displayProp '// Tool: ' str_toolType '// Source:' str_srcType]);
xlabel(app.ViewPanel, 'Horizontal Offset (m)');
ylabel(app.ViewPanel, 'Vertical Offset (m)');
colorbar(app.ViewPanel, 'vert')
set(app.ViewPanel, 'fontsize', 14)
xlim(app.ViewPanel, app.loc_data.windowLocation.X);
ylim(app.ViewPanel, app.loc_data.windowLocation.Z);
@Nick Bennett, I'm trying to think back to that answer in Nov 2019 and I think this is what's happening.
My answer refers to datacursormode() which can be enabled independently from the data tip tool in the axis toolbar. When I check the Enable property of datacursormode (dcm) in an app figure, it's set to 'off', however for some objects, the datatip appears when a point is clicked.
For example, using a simple line plot in App Designer (shown below), the dcm is set to Enable=off but if I click on a point, the datatip appears (note that the datatip does not appear in the axis toolbar).
But for plots produced by imagesc, clicking a section of the plot does not reveal a data tip by default. If you sent dcm to Enable=on then the datatip appears after clicking on the object. (again,the datatip tool does not appear in the axis toolbar).
dcm = datacursormode(app.UIFigure);
dcm.Enable = 'on';
Thanks Adam for your reply. Much appreciated.
I placed the two lines of code you suggested in my startupFcn before the call to the function where I draw the user interface. The function drawMainWindow(app) contains the lines I mentioned in my earlier post.
Somehow I also had the call to
enableDefaultInteractivity(app.ViewPanel)
in my code. Not sure if this causes unexpected issues.
function startupFcn(app, varargin)
... some details related to data loading
% prepare user interface
dcm = datacursormode(app.UIFigure);
dcm.Enable = 'on';
drawMainWindow(app); % draw main window
enableDefaultInteractivity(app.ViewPanel);
end
I can place data cursors along the line I plotted earlier. However, when I try to place a data cursor in region where I plotted using imagesc, then I see an issue with how the tooltip message is formulated. Suggestions? At the end of the day, I am not so interested in placing points along the line as much as I am interested in placing points in the plot produced by imagesc.
I will have to spend more time looking at your suggestion in more detail in the context of my example before coming to a conclusion on this, however. Thanks again.
Great! The functionality you highlight is precisely what we need to help migrate some of our GUIDE applications to appdesigner. Thank you again, Adam, for your expert advice and assistance on this. Much appreciated.
Thanks for the feedback, Nick.
If you wanted to format the datatip to make it appear like the default style, you can follow another demo of mine in this comment:

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 16 Nov 2019

Commented:

on 18 Oct 2020

Community Treasure Hunt

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

Start Hunting!