what is subplot and how to use it?

500 Ansichten (letzte 30 Tage)
monali
monali am 5 Okt. 2012
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 14 Nov. 2024
Bearbeitet: MathWorks Support Team am 14 Nov. 2024
Imagine an N by M array of little graphs on your figure. Those are the rows and columns. The third arg is the number of the plot starting at 1 in the upper left, going across the top row to M, then down a row and across again, then so on down row by row until the last plot, the (N*M)th, is at the lower right. For example for a 3 by 4 array of plots you'd do subplot(3, 4, plotNumber); Where plotNumber follows this pattern: 1 2 3 4 5 6 7 8 9 10 11 12 Use the number above to plot into the plot at that location. For example subplot(3,4,5); plot(rand(15,1)); will plot into the middle row at the far left. You can also combine numbers. for example you could plot all the way across the top row with subplot(3, 4, 1:4) and then have 8 tiny plots underneath it when you use the numbers 5 - 12 one at a time: subplot(3, 4, 5), subplot(3, 4, 6) etc.
  3 Kommentare
Eric Yokie
Eric Yokie am 16 Jun. 2020
This is fantastic. This didn't make sense to me when i read the help on subplot, but reading this makes it crystal clear. (Also, now the help file makes sense.) Thank you.
MathWorks Support Team
MathWorks Support Team am 2 Sep. 2020
Starting in R2019b, the tiledlayout and nexttile functions provide functionality that is similar to subplot, but they also allow more flexibility, such as adjusting the spacing between tiles, and being able to create a tiling that is not limited to a predetermined number of tiles, and creating shared axis labels. Starting in R2020b, you can also designate a tile for displaying a shared legend or colorbar.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Benjamin Kraus
Benjamin Kraus am 30 Okt. 2023
Bearbeitet: Benjamin Kraus am 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 Kommentare
Sagnik
Sagnik am 2 Jul. 2024
minor typo .. it should be nexttile (not nextile)
Benjamin Kraus
Benjamin Kraus am 2 Jul. 2024
@Sagnik: Thanks. I've fixed it.

Melden Sie sich an, um zu kommentieren.


Matt Fig
Matt Fig am 5 Okt. 2012
figure
subplot(1,2,1)
plot(1:10)
subplot(1,2,2)
plot((1:10).^2)
help subplot
  5 Kommentare
Olivier GARRIGUES
Olivier GARRIGUES am 6 Okt. 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
Image Analyst am 6 Okt. 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by