How to put stacked plots in the same graph

Illustration
johnwilson92 - 2020-08-31T10:57:17+00:00
Question: How to put stacked plots in the same graph

Hi, I want to put eleven plots in the same graph but separately i. e. all them will be in same x axis but in different scales in the y axis. For example: first graphic starts in 0 value in y axis, second plot starts in 100 value in the y axis and so on.

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

To plot the data all in the same plot, do something like the following.

 

x1 = 0:.01:1;
y1 = x1.^2;
x2 = .5:.1:1;
y2 = -1*x2 + 10;
fHand1 = figure;
aHand1 = axes('parent', fHand1);
hold(aHand1, 'on')
plot(x1, y1, 'parent', aHand1);
plot(x2, y2, 'parent', aHand1);

To make the plots scale independent - so the min of the plot is at the bottom and the max is at the top - you need to normalize the y values before plotting. In this case, it helps to remove the y axis labels to avoid confusion. Here is how I did it.

y1 = (y1 - min(y1)) / (max(y1) - min(y1));
y2 = (y2 - min(y2)) / (max(y2) - min(y2));
fHand2 = figure;
aHand2 = axes('parent', fHand2);
hold(aHand2, 'on')
plot(x1, y1, 'parent', aHand2);
plot(x2, y2, 'parent', aHand2);
set(aHand2, 'YTickLabel', [])


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!