How can I set the text font style of a Data Cursor object?

42 views (last 30 days)
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
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.
  1 Comment
Walter Roberson
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');

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!