Data Tip properties do not persist

4 visualizaciones (últimos 30 días)
AMM
AMM el 23 de Jul. de 2020
Comentada: AMM el 17 de Ag. de 2020
I made a custom data tip function to show in-depth info about points in a plot. It works as expected. However, I'm having trouble getting the properties of the text in the data tip popups to stick. Currently, I set up these tips as follows (following Walter Roberson's suggestion regarding hggroup objects):
dcm = datacursormode(h_fig);
set(dcm, 'UpdateFcn', {@myTooltip, myData});
% Set tooltip font to make it readable (lots of numbers!)
alldatacursors = findall(h_fig, 'type', 'hggroup', '-property', 'FontSize');
set(alldatacursors, 'FontSize', 14, 'FontName', 'Consolas');
Unfortunately, when I create a data tip by clicking on a point in the plot, the result is rendered in a default font and size (Helvetica 10?), not Consolas 14. Only if I manually execute the statements above a second time (either from the Command Window, or by highlighting them in the Editor and choosing Evaluate Selection from the context menu) does the font style/size get updated. Maddeningly, if I then create a second data tip, it comes up in the default font again.
Can anyone spot my error(s)? Am I simply mis-applying the datacursormode mechanism and/or hggroup properties?

Respuesta aceptada

Alan Moses
Alan Moses el 14 de Ag. de 2020
Hi,
You can try pasting both the lines of code where the font size is initialized, inside the ‘UpdateFcn’ of the datacursormode function. This ensures the data tip properties persist. For example:
x = 1:10;
y = x.^2;
h_fig = figure;
scatter(x,y)
dcm = datacursormode;
dcm.Enable = 'on';
dcm.UpdateFcn = {@displayCoordinates,h_fig};
function txt = displayCoordinates(~,info,h_fig)
x = info.Position(1);
y = info.Position(2);
txt = ['(' num2str(x) ', ' num2str(y) ')'];
alldatacursors = findall(h_fig, 'type', 'hggroup', '-property', 'FontSize');
set(alldatacursors, 'FontSize', 20, 'FontName', 'Rockwell');
end
Hope this helps!
  1 comentario
AMM
AMM el 17 de Ag. de 2020
This worked perfectly. Thanks Alan!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by