【问题标题】:How to change the font size of clustergram in Matlab?如何在 Matlab 中更改 clustergram 的字体大小?
【发布时间】:2013-01-30 00:29:45
【问题描述】:

我一直试图在 Matlab 中手动或通过编写命令来更改 clustergram 的字体大小。然而,他们都没有工作。我不知道我哪里做错了。我也在网上搜索过,但只能找到没有答案的类似问题。这是我尝试过的。

clusterobj = clustergram(data,'Rowlabel',c) % c is a cell array of strings for rowlabel
h = addYLabel(clusterobj);
set(h,'FontSize',2);

或类似的东西

addYLabel(clusterobj, c, 'FontSize', 2);

set(gca,'FontSize',2);

他们都没有工作。我只是希望将 c 数组中字符串的字体大小更改为更小的大小。有人知道吗?非常感谢,

【问题讨论】:

标签: matlab plot font-size heatmap axis-labels


【解决方案1】:

试试这个

addYLabel(clusterobj , 'YourLabel', 'FontSize', 4)

这将改变将出现在绘图右侧的 y 标签“YourLabel”的大小。

但是,如果你想改变所有的文字标签,那么这条路就有点长了。使用这个代码,我发现搜索TMW support pages:

% Make all handles visible. This is necessary because clustergram
% objects are created with 'HandleVisibility' property set to 'off'.
set(0,'ShowHiddenHandles','on')

% Get all handles from root
allhnds = get(0,'Children');

% Find the handles that correspond to clustergram objects
cgfigidx = strmatch('Clustergram',get(allhnds,'Tag'));
cffighnd = allhnds(cgfigidx);
fch = get(cffighnd,'Children');
fch = fch(strmatch('axes',get(fch,'Type')));

% Find all the text objects
txtobj = findall(fch,'Type','Text');

% Set the font size of all text objects in clustergram (at last!)
set(txtobj,'FontSize',5)

编辑: 只需阅读@Jonas 评论,有一种更简单、更优雅的方式,而不是复杂的代码:

figureHandle = gcf;
%# make all text in the figure to size 14 and bold
set(findall(figureHandle,'type','text'),'fontSize',4,'fontWeight','bold')

起首部分,乔纳斯先生。

【讨论】:

  • 谢谢。我假设您不是刚刚否决其他答案的人:)
  • 我对所链接问题的回答。
  • 感谢 SO 我知道我实际上是在 2012 年 10 月 4 日下午 3:57 投票赞成它并忘记了它:-),如果我知道得更好,我会链接到它马上……
  • 非常感谢大家。我尝试了第一个 addYLabel() 方法,但它不起作用。长代码和乔纳斯的方法奏效了。但是,如果我调整 clustergram 的大小,字体大小会跳回原始大小。我认为这些解决方案对我来说已经足够好了。
  • 如果有人还需要更改 Clustergram 中文本的字体大小,Jonas 的 cmets 在 Matlab 2010a 中工作,而不是在 2008a 中。
猜你喜欢
  • 2012-02-14
  • 1970-01-01
  • 1970-01-01
  • 2013-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-02
相关资源
最近更新 更多