Figure & subplot with Matlab
Matlab is a high level programming software, which enable drawing a wide variety of complex plots. Among others,subplot
function can be used to manage
several plots inside a single one.
Subplot matrix
Inside an active figure (unless creating it if not existing),subplot(n,p,t)
command allows one to cut the figure into
sub-figures: nxp
sub-figures, arranged
along n
lines and p
columns.
The last argument, the integer
t
points to the one
sub-figure which is actived and waiting for plot commands.
Without ambiguity,
subplot(npt)
can be called,
that is if n
, p
and t
are
integers strictly lower than 10.
For example, with the script
clear all;close all;
subplot(361),text(.4,.5,'1','fontsize',18,'fontweight','bold','color','red')
subplot(362),text(.4,.5,'2','fontsize',18,'fontweight','bold','color','red')
subplot(363),text(.4,.5,'3','fontsize',18,'fontweight','bold','color','red')
subplot(364),text(.4,.5,'4','fontsize',18,'fontweight','bold','color','red')
subplot(365),text(.4,.5,'5','fontsize',18,'fontweight','bold','color','red')
subplot(366),text(.4,.5,'6','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,7),text(.4,.5,'7','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,8),text(.4,.5,'...','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,11),text(.4,.5,'...','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,12),text(.3,.5,'12','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,13),text(.3,.5,'13','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,14),text(.4,.5,'...','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,17),text(.4,.5,'...','fontsize',18,'fontweight','bold','color','red')
subplot(3,6,18),text(.3,.5,'18','fontsize',18,'fontweight','bold','color','red')
the 18 following sub-figures are plotted:
Free sub-plotting
subplot
command can also be used with
argument 'position'
as subplot('position',[left bottom width height])
where
[left bottom width height]
is a 4-dimensionnal
vector, each number, being a percentage, of which pointing out to
the very location of the subplot, respectively, from left and bottom
of the figure,
and then the width and height of the area.
For example, the script:
clear all;close all;
figure(1);
subplot('position',[0.1 0.2 0.2 0.7])
x=-2*pi:0.01:2*pi;plot(x,sin(x))
text(11,0.7,'Quelques oscillations','rotation',-90,'fontsize',12)
subplot('position',[0.5 0.7 0.4 0.2])
x=-1:0.1:3;plot(x,exp(x))
text(-.9,25,'Un peu d''exponentielle')
subplot('position',[0.4 0.1 0.5 0.4])
x=0.1:0.1:3;plot(x,log(x))
text(0.5,2.2,'Et un peu de logarithme','fontsize',14)
gives the figure: