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

title with subplot

2 views
Skip to first unread message

Benito

unread,
Jan 8, 2001, 10:06:56 PM1/8/01
to
I want to create a title in a figure with 4 subplots. But i want a great
title for the figure and diferent titles for each subplots...
Thanks for the help


Ioan (Nelu) Buciu

unread,
Jan 9, 2001, 4:41:31 AM1/9/01
to
Benito wrote:

Dear Matlab user,

You can do it in this way. I give you an example:

subplot(2,2,1)
title('Title1','FontName','Times','Fontsize',6)
subplot(2,2,2)
title('Title2','FontName','Times','Fontsize',8)
subplot(2,2,3)
title('Title3','FontName','Times','Fontsize',10)
subplot(2,2,4)
title('Title4','FontName','Times','Fontsize',12)
text(-0.35,2.52,'Title','FontName','Times','Fontsize',16)

or you can use

gtext({'Title'},'FontName','Times','Fontsize',16)

instead of last line (if you want to put the text by help of mouse).
I hope it will help you.

Best redargs,

Ioan Buciu
Computer Science Department,
Aristotle University of Thessaloniki.


Michael Robbins

unread,
Jan 9, 2001, 9:09:17 PM1/9/01
to
Use the title command for the subplots:

subplot(2,2,1);
title('first');

subplot(2,2,2);
title('second');

etc.

For the figure title, use suptitle. You can find in on TMW website
under user downloads.

--
Michael Robbins, CFA
Director, Debt Capital Markets
Canadian Imperial Bank of Commerce, World Markets
New York


Sent via Deja.com
http://www.deja.com/

John Cristion

unread,
Jan 10, 2001, 8:01:53 AM1/10/01
to
I found this at the MATLAB site under user contributed m files. Works
well for me.

John

______________________________________________________________

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

Michael Robbins

unread,
Jan 10, 2001, 3:16:51 PM1/10/01
to
Yes that's it, but I don't know if it's OK to post it like that.

Jan Even Nilsen

unread,
Jan 10, 2001, 4:11:16 PM1/10/01
to
Michael Robbins wrote:

> Yes that's it, but I don't know if it's OK to post it like that.

Why should it not?

It has got the signatures in it, and it is already posted to an open
site. This just saves us the hustle of going there to look at it and
then download it.

Even Nilsen


0 new messages