Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Title of figure with subplots

1 view
Skip to first unread message

Scott Perman

unread,
Sep 13, 2001, 9:42:30 AM9/13/01
to
I have a figure with four sub plots. Each subplot has a title. Is
it possible to create a title for the entire figure? for example

              Title of the entire figure

subplot 1 title subplot 2 title
subplot1 subplot2
subplot1 subplot2
subplot1 subplot2

subplot 3 title subplot 4 title
subplot3 subplot4
subplot3 subplot4
subplot3 subplot4

Perttu Ranta-aho

unread,
Sep 13, 2001, 9:53:05 AM9/13/01
to
"Scott Perman" <spe...@hmsracing.com> writes:

> I have a figure with four sub plots. Each subplot has a title. Is
> it possible to create a title for the entire figure? for example
>

You have to use invisible background axes. Try following code:

bg_ax = axes('units','normal','position',[0 0 1 1],...
'xlim',[0 1],'ylim',[0 1],'visible','off');
text(0.5,0.95,'Title of the entire figure',...
'parent',bg_ax,...
'HorizontalAlign','center');

You may have to iterate y-coordinate (0.95) to get the title to the
right place.

--
Perttu Ranta-aho | Perttu.R...@uku.fi
Department of Applied Physics | http://venda.uku.fi
University of Kuopio, Finland | http://www.uku.fi

John Cristion

unread,
Sep 13, 2001, 10:25:04 AM9/13/01
to
function hout=suptitle(str)
%SUPTITLE Puts a title above all subplots.
% SUPTITLE('text') adds text to the top of the figure
% above all subplots (a "super title"). Use this function
% after all subplot commands.

% Drea Thomas 6/15/95 dr...@mathworks.com

% John Cristion 12/13/00 modified

% Warning: If the figure or axis units are non-default, this
% will break.

% This will disable sub- and super-scripts (JAC)

set(0,'DefaultTextInterpreter','none');

% Parameters used to position the supertitle.

% Amount of the figure window devoted to subplots
plotregion = .92;

% Y position of title in normalized coordinates
titleypos = .95;

% Fontsize for supertitle
%fs = get(gcf,'defaultaxesfontsize')+4;

fs = get(gcf,'defaultaxesfontsize');

% Fudge factor to adjust y spacing between subplots
fudge=1;

haold = gca;
figunits = get(gcf,'units');

% Get the (approximate) difference between full height (plot + title
% + xlabel) and bounding rectangle.

if (~strcmp(figunits,'pixels')),
set(gcf,'units','pixels');
pos = get(gcf,'position');
set(gcf,'units',figunits);
else,
pos = get(gcf,'position');
end
ff = (fs-4)*1.27*5/pos(4)*fudge;

% The 5 here reflects about 3 characters of height below
% an axis and 2 above. 1.27 is pixels per point.

% Determine the bounding rectange for all the plots

% h = findobj('Type','axes');

% findobj is a 4.2 thing.. if you don't have 4.2 comment out
% the next line and uncomment the following block.

h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills

% If you don't have 4.2, use this code instead
%ch = get(gcf,'children');
%h=[];
%for i=1:length(ch),
% if strcmp(get(ch(i),'type'),'axes'),
% h=[h,ch(i)];
% end
%end


max_y=0;
min_y=1;

oldtitle =0;
for i=1:length(h),
if (~strcmp(get(h(i),'Tag'),'suptitle')),
pos=get(h(i),'pos');
if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
else,
oldtitle = h(i);
end
end

if max_y > plotregion,
scale = (plotregion-min_y)/(max_y-min_y);
for i=1:length(h),
pos = get(h(i),'position');
pos(2) = (pos(2)-min_y)*scale+min_y;
pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
set(h(i),'position',pos);
end
end

np = get(gcf,'nextplot');
set(gcf,'nextplot','add');
if (oldtitle),
delete(oldtitle);
end
ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
set(gcf,'nextplot',np);
axes(haold);
if nargout,
hout=ht;
end

Lucio Andrade

unread,
Sep 13, 2001, 10:34:01 AM9/13/01
to
You can always use text to place text whereever you want, even outside
the axis, here I post my solution where you readjust the size of the
other subplots, otherwise you could have problems when printing
or when resizing the windows....hope it helps

Lucio Andrade

subplot('position',[.10 .05 .35 .35]);title('subplot 1')
subplot('position',[.10 .50 .35 .35]);title('subplot 2')
subplot('position',[.60 .05 .35 .35]);title('subplot 3')
subplot('position',[.60 .50 .35 .35]);title('subplot 4')
subplot('position',[.10 .90 .80 .01]);axis off;
title('Overall title','Fontsize',16)

>
>
> "Scott Perman" <spe...@hmsracing.com> writes:
>
>> I have a figure with four sub plots. Each subplot has a
> title. Is
>> it possible to create a title for the entire figure?
> for example
>>
>

> You have to use invisible background axes. Try following
> code:
>
> bg_ax = axes('units','normal','position',[0 0 1 1],...
> 'xlim',[0 1],'ylim',[0 1],'visible','off');
> text(0.5,0.95,'Title of the entire figure',...
> 'parent',bg_ax,...
> 'HorizontalAlign','center');
>
> You may have to iterate y-coordinate (0.95) to get the
> title to the
> right place.
>
> --
> Perttu Ranta-aho | Perttu.R...@uku.fi

> Department of Applied Physics | http://venda.uku.fi <http://venda.uku.fi>
> University of Kuopio, Finland | http://www.uku.fi <http://www.uku.fi>
>

scott perman

unread,
Sep 13, 2001, 10:55:58 AM9/13/01
to
Thanks for all of your help. I now have it working.
0 new messages