How can I set the text font style of a Data Cursor object?
15 views (last 30 days)
Show older comments
MathWorks Support Team
on 12 Sep 2013
I have created a data cursor object on a plot. Is it possible to customize the font style, size, and/or weight for the text in the data cursor object?
Accepted Answer
MathWorks Support Team
on 26 Mar 2019
Edited: MathWorks Support Team
on 26 Mar 2019
You can customize the font style, size, or weight of the text in data cursors by using the following commands:
alldatacursors = findall(gcf,'type','hggroup')
set(alldatacursors,'FontSize',12)
set(alldatacursors,'FontName','Times')
set(alldatacursors, 'FontWeight', 'bold')
The options for 'FontWeight' are 'bold' or 'normal'. Please note that the text may appear to be the same weight for both 'bold' and 'normal' depending on the font chosen, as not all fonts have a bold weight.
You can find a list of available fonts by using the command;
listfonts
The ability to set specific default fonts for data cursors is not currently available. However, one can set the default styles and sizes for all plots. This can be done as follows:
set(0,'DefaultTextFontName','Script') % Sets Font Style
set(0,'DefaultTextFontSize',10) % Sets font size
This must be done before any figures are created or launched. A recommended place for this command is in the "startup.m" file.
2 Comments
Walter Roberson
on 26 Mar 2019
hggroup are pretty general objects, and it is not clear that all of them will have font related properties. Even if we exclude the difficulty that not all hggroup with font properties will have to do with data cursors, we should narrow the search down, such as
alldatacursors = findall(gcf, 'type', 'hggroup', '-property', 'FontSize');
DGM
on 19 Aug 2025
Edited: DGM
on 19 Aug 2025
As far as I know, PointDataTip properties aren't documented
You can set some text properties from the parent DataTip object, but not 'FontWeight'.
% get all DataTip objects
alldatacursors = findall(gcf,'type','datatip');
% now you can set the properties of the datatips
set(alldatacursors,'FontSize',18)
set(alldatacursors,'FontName','Times')
If you want to set other properties via the child PointDataTip object, you can narrow down the search to avoid picking up other hggroup objects:
% get all PointDataTip objects
% this gets all hggroups -- but an hggroup can be any number of things
alldatacursors = findall(gcf,'type','hggroup');
% so just keep the hggroups which are also datatips
f = @(x) isa(x,'matlab.graphics.shape.internal.PointDataTip');
alldatacursors = alldatacursors(arrayfun(f,alldatacursors));
% now you can set potentially undocumented properties of the datatips
set(alldatacursors,'FontSize',20)
set(alldatacursors,'FontName','Times')
set(alldatacursors,'FontWeight','bold')
set(alldatacursors,'Orientation','bottomright')
set(alldatacursors,'MarkerSize',10)
If you're generating the datatips programmatically, you can get the handles to the parent DataTip objects directly during creation, but as far as I can tell, we are prevented from directly accessing the handle to the child PointDataTip object without the roundabout search for it.
... at least that's what I've managed to figure out.
More Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!