Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give a combined title for subplots? [duplicate]

I want to give a combined title to my subplots, instead of titling each plot individually. e.g;

for pl=1:4
      subplot(2,2,pl)
      title('Test') 
end

gives me this:enter image description here

If I use this:

figure
title('Test') 
for pl=1:4
      subplot(2,2,pl)

end

I don't get any title.

I want my output like the following:enter image description here

like image 208
Sardar Usama Avatar asked May 03 '16 20:05

Sardar Usama


1 Answers

There is a small trick. You can do the following to spawn a figure with multiple subplots.

h = figure 
for pl=1:4
    subplot(2,2,pl)
end

After this you have to set the NextPlot property to 'add'. Do this:

h.NextPlot = 'add';
a = axes; 

%// Set the title and get the handle to it
ht = title('Test');

%// Turn the visibility of the axes off
a.Visible = 'off';

%// Turn the visibility of the title on
ht.Visible = 'on';

Hope this helps!

like image 141
Amal Avatar answered Nov 01 '22 11:11

Amal