How do I change the figure size with subplots?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When you create subplots in Matplotlib, figure size is controlled at the figure level, not separately for each axis. The usual answer is to pass figsize=(width, height) to plt.subplots, or to change the size later with fig.set_size_inches.
Set the Size When You Create the Figure
The most common pattern is to define the size up front:
The figsize values are in inches. Matplotlib combines those dimensions with the figure DPI to determine the final pixel size when rendering or saving.
This is usually the cleanest solution because layout engines such as tight_layout or constrained_layout can work with the correct geometry from the start.
Change the Size After Creation
If you already have a figure object, resize it later:
This is useful when figure size depends on data or when you are writing helper functions that receive an existing figure.
Understand the Relationship Between Size and Layout
Changing figure size does not automatically fix overlap. If subplot titles, tick labels, or legends are colliding, also use a layout tool:
constrained_layout=True is often the better default for new code. Older examples frequently use plt.tight_layout(), which still works well in many cases:
Think of figure size and layout as related but different knobs. A bigger figure gives elements more room, while the layout engine decides how that room is distributed.
Save the Figure at the Intended Output Size
If the plot looks right on screen but wrong in the saved file, check both figsize and DPI:
An 8 x 4 inch figure at 150 DPI produces a 1200 x 600 pixel image. That matters if the figure is destined for a slide deck, a notebook, or a printed document.
Pick Sizes Deliberately
There is no universal best figure size. A few practical defaults help:
- use something like
figsize=(6, 4)for a single small chart - use wider figures such as
figsize=(10, 4)for side-by-side subplots - increase height for stacked plots, especially when labels are long
If the subplot grid grows, increase the figure size proportionally instead of expecting the axes to stay readable at the old size.
Common Pitfalls
- Trying to resize subplots individually instead of changing the figure size. The axes live inside the figure.
- Forgetting that
figsizeis measured in inches, not pixels. - Enlarging the figure without addressing layout overlap. Use
constrained_layoutortight_layoutwhen labels collide. - Saving at an unexpected DPI and then wondering why the exported image is too small or too blurry.
- Creating a dense grid of subplots without increasing width and height proportionally.
Summary
- Pass
figsize=(w, h)toplt.subplotsto set the figure size up front. - Use
fig.set_size_incheswhen you need to resize an existing figure. - Combine figure sizing with
constrained_layoutortight_layoutfor readable spacing. - Remember that output size depends on both inches and DPI.
- Scale the figure with the complexity of the subplot grid instead of relying on defaults.

