Figure Subplot Tiles Customization

10 views (last 30 days)
I want to create a figure containing subplots such that there are 3 columns. The first two columns are supposed to have three subplots each row wise but the last column should have 2 tiles only. How can I do this using the subplot command? I've attached a sample picture of the figure that I want.

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 24 Jan 2023
Edited: Benjamin Kraus on 24 Jan 2023
I don't see an attached picture, but I think I understand what you are trying to do.
First, I recommend trying tiledlayout instead of subplot, but both can handle what you are trying to do. tiledlayout and nexttile are newer than subplot and provide a few new features that should make this tast easier.
Conceptually, what you want is a grid that is 6 rows and 3 columns, then you want tiles in the grid to be either 2 or 3 rows tall.
For example, using tiledlayout and nexttile:
t = tiledlayout(6,3);
ax11 = nexttile(1,[2 1]); % First column, top two rows
ax21 = nexttile(2,[2 1]); % Second column, top two rows
ax31 = nexttile(3,[3 1]); % Third column, top three rows
ax12 = nexttile(7,[2 1]); % First column, next two rows
ax22 = nexttile(8,[2 1]); % Second column, next two rows
ax32 = nexttile(12,[3 1]); % Third column, bottom three rows
ax13 = nexttile(13,[2 1]); % First column, bottom two rows
ax23 = nexttile(14,[2 1]); % Second column, bottom two rows
If you prefer subplot you do this with that as well:
figure
ax11 = subplot(6,3,[1 4]); % First column, top two rows
ax21 = subplot(6,3,[2 5]); % Second column, top two rows
ax31 = subplot(6,3,[3 6 9]); % Third column, top three rows
ax12 = subplot(6,3,[7 10]); % First column, next two rows
ax22 = subplot(6,3,[8 11]); % Second column, next two rows
ax32 = subplot(6,3,[12 15 18]); % Third column, bottom three rows
ax13 = subplot(6,3,[13 16]); % First column, bottom two rows
ax23 = subplot(6,3,[14 17]); % Second column, bottom two rows
  4 Comments
Fawad Farooq Ashraf
Fawad Farooq Ashraf on 25 Jan 2023
Thank you. However, by doing it this way, the individual xlabels of the subplots are now hidden behind other subplots below them. How can I fix that?
Benjamin Kraus
Benjamin Kraus on 25 Jan 2023
@Fawad Farooq Ashraf: You shouldn't have that problem with either subplot or tiledlayout, but out of curiosity: Which one are you using?
It should be fairly difficult to have that issue with tiledlayout.
There are lots of ways to accidentally cause an axes to "break out" of a subplot, which can cause this issue. I suggest using tiledlayout if you are not already.
Either way, if you want assistance fixing that issue, post your code so I can get a better idea of what might be happening.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!