35 views (last 30 days)

I make the plots by the following code using subplots

subplot(2,1,1)

for i=2:size(data,1)

plot_fig(i) = plot(data(1,:),data(i,:),'LineWidth',2.5);

hold on

end

subplot(2,1,2)

plot_fig = plot(data(1,:),y_2(2,:),'LineWidth',2.5);

But I was wondering if can do the same but using stackedplot() considering that my top plot will have multiple plots in it.

The x-axis is same for the above 2 plots. That means these plots can be a stacked plot.

VBBV
on 19 Nov 2020

tbl = readtable('stacked.xlsx');

Vars = {{'A','B','C','D','E'},'F'}; % assuming 6 variable names(Var1 ...Var6) as A,B... E, Five of them plotted as one and remaing seperately

stackedplot(tbl,Vars)

VBBV
on 19 Nov 2020

Vars = {{'B','C','D','E'},'F'};

xvar = "A";

stackedplot(tbl,Vars,'XVariable',xvar)

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 9 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1142058

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1142058

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1142118

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1142118

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1142843

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1142843

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1144818

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1144818

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1144948

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1144948

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1144963

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1144963

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1145168

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1145168

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1145173

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1145173

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1145513

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/651613-how-to-make-stack-plot-with-y-axis-consisting-of-multiple-plots#comment_1145513

Sign in to comment.