2

I have been trying to change the font size of clustergram in Matlab manually or by writing commands. However, none of them worked. I don't know where I did wrong. I also googled online but can only find similar questions without answers. Here are what I have tried.

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

or something like

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

or

set(gca,'FontSize',2);

None of them worked. I just hope to change the font size of strings in c array to much smaller size. Anyone has any idea ? Thank you very much,

bla
  • 25,846
  • 10
  • 70
  • 101
Cassie
  • 1,179
  • 6
  • 18
  • 30
  • 1
    Do the answers to [this similar question](http://stackoverflow.com/questions/8934468/changing-fonts-in-matlab-plots/8934614#8934614) help? – Jonas Jan 30 '13 at 00:38

1 Answers1

5

try this

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

this will change the size of the y-label 'YourLabel' that will appear on the right side of the plot.

However, if you want to change all the text labels, then the road is a bit longer. Use this code, that I have found searching 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)

EDIT: Just reading @Jonas comment , there's a much easier and more elegant way instead of the elaborate code:

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

Chapeau, Monsieur Jonas.

bla
  • 25,846
  • 10
  • 70
  • 101
  • Thanks. I assume you aren't the person who just downvoted that other answer :) – Jonas Jan 30 '13 at 01:15
  • my answer to the question I linked. – Jonas Jan 30 '13 at 01:19
  • Thanks to SO I've learned that I actually up-voted it on 4th Oct 2012 at 3:57 and forgot about it :-), if I had known better I'd have linked to it right away... – bla Jan 30 '13 at 01:21
  • Thank you all very much. I tried the first addYLabel() method and it did not work. The long codes and Jonas' method worked. However, if I resize the clustergram, the font size jumped back to the original size. I think those solutions are good enough for me. – Cassie Jan 30 '13 at 02:02
  • 1
    In case someone also needs to change the font size of text in Clustergram, the comments from Jonas work in Matlab 2010a not in 2008a. – Cassie Apr 08 '13 at 01:41