Show datatips in a logarithmically scaled uiaxes

298 Views Asked by At

I have encountered a problem using the new uiaxes object: after plotting my data, I can click on the data points then it will show a datatips displaying the X and Y data. When I change the scale of my X axis into a logarithmic one datatips won't display.

I am using MATLAB 2019a.

Here is a sample code :

h = uiaxes;
h.XScale = 'log';
a = plot( 1 : 10 );

By changing the scale back to linear, the datatips would display correctly again.

I also tried the below command in order to enable the datatips, it works but I have a ton of warnings on my command window saying an error occurred in the WindowMouseMotion Callback.

cursorMode = datacursormode(h.Parent);
cursorMode.Enable = 'on'
1

There are 1 best solutions below

0
On

Check this out:

function [] = q56982381()
hF = uifigure(); hAx = uiaxes(hF);
hAx.XScale = 'log';
hP = plot( hAx, 1 : 10 );

% Invoke the datacursor manager:
dcm_obj = datacursormode(hF);
hTip = dcm_obj.createDatatip(hP); % Don't specify any further inputs at this stage

% Wait until the figure loaded:
drawnow; pause(0.1); % or mlapptools.waitForFigureReady(hF); (see note at the bottom)

% Modify the datatip position:
hTip.Position = [2, 2, 0];

Results in:

enter image description here

The mlapptools utility, which I co-authored, is meant to help work with and customize UIFigures.