Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Title over group of subplots

there are many subplots and each subplot has its own title. how can add a title over all of these group of subplots? I want this title to be shown at top center.

x = linspace(-5,5);

y1 = sin(x);
subplot(2,5,[1:2])
plot(x,y1)
title('y=sin(x)')

y2 = cos(x);
subplot(2,5,[3:4])
plot(x,y2)
title('y=cos(x)')

y3 = tan(x);
subplot(2,5,[5,10])
plot(x,y3)
title('y=tan(x)')

y4 = sin(2*x);
subplot(2,5,[6:7])
plot(x,y1)
title('y=sin(2x)')

y5 = cos(2*x);
subplot(2,5,[8:9])
plot(x,y2)
title('y=acos(2x)')
like image 210
Woeitg Avatar asked Nov 08 '15 12:11

Woeitg


People also ask

How do you put a title over all subplots?

There is a command suptitle, which puts the title of all subplots.

How do you give a subplot a main title in Matlab?

Accepted Answer Control over the spacing between the plots and around the edges of the layout. An option for a shared title at the top of the layout. Options for shared x- and y-axis labels. An option to control whether the tiling has a fixed size or variable size that can reflow.


1 Answers

The simplest way I have found for people without the bioinformatics toolbox is this:

a = axes;
t = title('My title');
a.Visible = 'off';
t.Visible = 'on';

What you're doing is creating a new set of axes which, by default, covers the whole figure, and creating a title on those axes. Then the axes are made invisible, and this is overridden for the title which is made visible again.

If the resulting title collides with things, fiddle with a.Position to move the axes around.

Yes, it's ridiculous that this isn't part of base functionality, but there are plenty of one- or two-line functions hidden in toolboxes that one might say that about ;-) (looking at you, range.)

like image 154
Flyto Avatar answered Oct 13 '22 21:10

Flyto