Data Tip properties do not persist
10 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Alan Moses
2020-8-14
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!