100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Subplots and Figure Customization

Arrange multiple plots within a single figure using subplot and tiledlayout, and customize figure-level properties like size, background, and axes limits.

Plotting & DataBeginner9 min readJul 10, 2026
Analogies

Arranging Multiple Axes with subplot

subplot(m, n, p) divides the current figure into an m-by-n grid of axes and makes the p-th cell (numbered left-to-right, top-to-bottom) the active axes for the next plotting command. For example, subplot(2, 2, 3) creates a 2x2 grid and activates the bottom-left cell. You can also pass a vector for p, such as subplot(2, 2, [1 2]), to merge multiple grid cells into one wider axes spanning the first row. Each call to subplot(m,n,p) with the same m and n reuses the same grid layout, so you typically call it once per panel just before the corresponding plot() command.

🏏

Cricket analogy: subplot(2,2,3) picking the bottom-left cell is like a TV broadcast's four-way split screen dedicating one quadrant to the bowler's-eye view while others show the pitch map and scorecard.

matlab
figure;
subplot(2,2,1);
plot(x, sin(x)); title('Sine');

subplot(2,2,2);
plot(x, cos(x)); title('Cosine');

subplot(2,2,[3 4]);
plot(x, tan(x)); ylim([-10 10]); title('Tangent (wide panel)');

tiledlayout for More Flexible Grids

Introduced in R2019b, tiledlayout(m, n) is the modern alternative to subplot, offering better control over spacing via the 'TileSpacing' and 'Padding' name-value arguments and supporting tiles that span multiple rows or columns via nexttile(span). A typical pattern is t = tiledlayout(2,2,'TileSpacing','compact'); followed by repeated nexttile; plot(...) calls, which automatically advance to the next open tile in order. Unlike subplot, tiledlayout also supports a shared title and shared axis labels for the whole layout via title(t, 'Overall Title') and xlabel(t, 'Shared X Label'), avoiding repetitive per-axes labeling.

🏏

Cricket analogy: A shared title(t,'...') across a tiledlayout of four bowlers' spell analyses is like one match-summary header sitting above four separate over-by-over graphs in a post-match report.

Figure-Level Customization

The figure() function itself accepts name-value properties such as 'Position', [left bottom width height] in pixels to control window size and placement, and 'Color', 'w' to set the background color, which matters when exporting for print since MATLAB's default figure background is a light gray. Axis limits are controlled per-axes with xlim([xmin xmax]) and ylim([ymin ymax]), while axis equal forces equal scaling on both axes so that circles appear circular rather than elliptical — critical for plotting geometric data. sgtitle('Overall Title') adds a single title spanning subplot-based grids, serving the same purpose as tiledlayout's title(t,...) for figures built with the older subplot function.

🏏

Cricket analogy: axis equal ensuring a circle stays circular is like a pitch-map graphic keeping the field's radial distances proportionally accurate rather than stretching them into an oval.

tiledlayout is generally preferred over subplot in modern MATLAB code (R2019b+) because it handles spacing automatically, supports shared titles/labels, and resizes tiles more gracefully when the figure window is resized.

Mixing subplot and tiledlayout calls within the same figure is not supported — pick one approach per figure, since tiledlayout manages its own internal grid that subplot does not know how to coexist with.

  • subplot(m,n,p) creates an m-by-n grid and activates cell p for the next plot command.
  • A vector for p in subplot merges multiple grid cells into a wider or taller panel.
  • tiledlayout with nexttile is the modern replacement offering compact spacing and shared titles/labels.
  • figure('Position', [...]) controls window size and placement in pixels.
  • axis equal preserves true geometric proportions, essential for circles and maps.
  • sgtitle adds one title spanning an entire subplot-based figure.
  • Do not mix subplot and tiledlayout calls within the same figure.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#MATLABStudyNotes#SubplotsAndFigureCustomization#Subplots#Figure#Customization#Arranging#StudyNotes#SkillVeris#ExamPrep