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

17 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2013 年 9 月 12 日
編集済み: DGM 2025 年 8 月 19 日
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?

採用された回答

MathWorks Support Team
MathWorks Support Team 2019 年 3 月 26 日
編集済み: MathWorks Support Team 2019 年 3 月 26 日
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 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 26 日
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
DGM 2025 年 8 月 19 日
編集済み: DGM 2025 年 8 月 19 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

製品


リリース

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by