MATLAB: Multiply plot joined together

plottingsubplot

Hello, I would love to do a plot of this nature, three or more parameters having the same x-axis(stack on each other). The time is for six days. Kindly see the attached picture to get an understanding of what I want. Thanks.

Best Answer

Here is a demonstration of how to create three (or an arbitrary number of) plots vertically joined together:
% Fake data:
X = 0:0.1:8;
Y(:,3) = sin(X);
Y(:,2) = cos(X);
Y(:,1) = X.^2;
% Preallocate:
N = size(Y,2);
H = NaN(1,N);
% Plot each set of data:
figure()
for k = 1:N
H(k) = subplot(N,1,k);
plot(X,Y(:,k));
end
% Remove tick labels from upper axes:
set(H(2:N),'XTickLabel',{''})
% Get old axes position, calculate new "joined" position:
pos = cell2mat(get(H,'Position'));
ymx = pos(1,2)+pos(1,4);
ymn = pos(end,2);
hgt = (ymx-ymn)/N;
% Set new axes position:
pos(:,4) = hgt;
pos(:,2) = pos(end,2) + hgt*(0:N-1);
set(H,{'Position'}, num2cell(pos,2));
You will also have to consider the YtickLabel or tick marks, as these overlap in this example. It produces this figure: