what is subplot and how to use it?
Show older comments
i want to plot two graphs in one single window then how to do so? what is block? also give some hint on how join various elements and blocks while using simulink?
Accepted Answer
More Answers (2)
Benjamin Kraus
on 30 Oct 2023
Edited: Benjamin Kraus
on 2 Jul 2024
If you are using MATLAB R2019b or later, you should consider using tiledlayout and nexttile instead of subplot. tiledlayout and nexttile supports most of the features of subplot, and many more, and you should see better performance with tiledlayout and nexttile.
The tile layout is the same as subplot, but tiledlayout also supports a "flow" layout that will automatically adjust the number of rows and columns to optimally fit your axes. In addition, since MATLAB R2023a you can specify a "vertical" or "horizontal" layout that will stack your axes vertically or horizontally.
The equivalent to subplot(3, 4, plotNumber); with tiledlayout would be this:
tiledlayout(3,4)
nexttile(plotNumber)
2 Comments
Sagnik
on 2 Jul 2024
minor typo .. it should be nexttile (not nextile)
Benjamin Kraus
on 2 Jul 2024
@Sagnik: Thanks. I've fixed it.
Matt Fig
on 5 Oct 2012
figure
subplot(1,2,1)
plot(1:10)
subplot(1,2,2)
plot((1:10).^2)
help subplot
5 Comments
monali
on 7 Oct 2012
Prabin Rath
on 7 Jun 2018
1 to 10 with a spacing of 1. Like 1,2,3,4....
Olivier GARRIGUES
on 6 Oct 2023
Its the number of the plot, from top to bottom and left to right. So if you have a 1 by 2 plot, subplot(1,2,1) is the left one and subplot(1,2,2) the right one.
Image Analyst
on 6 Oct 2023
@Asim the first two numbers are the number of rows and columns in the layout of all the plots in a grid. The third number is the "number" of the particular single plot that is in the grid. For example if you have 3 rows and 4 columns, this chart gives the third number:
1 2 3 4
5 6 7 8
9 10 11 12
So for example if you wanted to make a plot in the second row and third column, that would be #7, so you'd do this
subplot(3, 4, 7)
and if you wanted to plot something in the third row, second column, that would be #10 and you'd call this before you called plot:
subplot(3, 4, 10);
Does that explain it better?
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!