Skip to content

Matplotlib figsize: How to Set Figure Size, DPI, and Subplots

Published on

Updated on

To set a figure's size in Matplotlib, pass figsize=(width, height) in inches when creating the figure or subplot grid. Matplotlib's default is (6.4, 4.8) inches at 100 DPI (640 × 480 pixels).

Use either plt.figure() for a single plot or plt.subplots() for the object-oriented workflow:

import matplotlib.pyplot as plt
 
# Option 1: pyplot state-machine style
plt.figure(figsize=(10, 5))
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.show()
 
# Option 2: object-oriented style (recommended for subplots & styling)
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.show()

Quick Reference: Every Way to Set Figure Size

TaskMethodExample
New single figureplt.figure(figsize=(w, h))plt.figure(figsize=(8, 5))
New figure + axes / gridplt.subplots(nrows, ncols, figsize=(w, h))fig, ax = plt.subplots(1, 2, figsize=(12, 4))
Resize an existing figurefig.set_size_inches(w, h)fig.set_size_inches(10, 6, forward=True)
Global default (notebook/script)plt.rcParams["figure.figsize"]plt.rcParams["figure.figsize"] = (10, 5)
Temporary size overrideplt.rc_context(...)with plt.rc_context({"figure.figsize": (12, 4)}):
Pandas plotdf.plot(figsize=(w, h))df["sales"].plot(figsize=(10, 4))
Size in pixelsDivide pixels by DPIfigsize=(1280 / dpi, 720 / dpi)
Size in centimetersDivide cm by 2.54figsize=(16 / 2.54, 9 / 2.54)
Trending reads

figsize, DPI, Pixels, and Centimeters Conversion Cheat Table

Matplotlib stores figure dimensions in inches and multiplies them by DPI (dots per inch) to determine the output pixel resolution:

  • pixels = inches × dpi
  • inches = pixels / dpi
  • inches = cm / 2.54
Use Casefigsize=(w, h) (inches)Centimeters (w × h)DPIOutput Pixels
Matplotlib default(6.4, 4.8)16.3 × 12.2 cm100640 × 480 px
Wide blog / notebook chart(10, 5)25.4 × 12.7 cm1001000 × 500 px
16:9 HD slide(12.8, 7.2)32.5 × 18.3 cm1001280 × 720 px
16:9 Full HD export(12.8, 7.2)32.5 × 18.3 cm1501920 × 1080 px
High-res print (half-page)(6.0, 4.0)15.2 × 10.2 cm3001800 × 1200 px
Journal single-column (8.5 cm)(3.35, 2.5)8.5 × 6.35 cm3001004 × 750 px
Journal double-column (17.8 cm)(7.01, 4.5)17.8 × 11.4 cm3002102 × 1350 px

Setting figsize in Exact Pixels

Divide your target pixel width and height by the same dpi value passed to subplots() and savefig():

import matplotlib.pyplot as plt
 
dpi = 150
width_px, height_px = 1920, 1080
 
fig, ax = plt.subplots(figsize=(width_px / dpi, height_px / dpi), dpi=dpi)
ax.plot([1, 2, 3], [2, 5, 3])
fig.savefig("chart_1080p.png", dpi=dpi)

Setting figsize in Centimeters

Define a small conversion constant (cm = 1 / 2.54)—the same pattern used in Matplotlib's official documentation for academic papers:

import matplotlib.pyplot as plt
 
cm = 1 / 2.54  # centimeters to inches
fig, ax = plt.subplots(figsize=(17.8 * cm, 10 * cm), dpi=300)
ax.plot([0, 1, 2], [0, 1, 4])
fig.savefig("journal_figure.png", dpi=300)

Set figsize on Subplots and Multi-Panel Layouts

In plt.subplots(nrows, ncols, figsize=(w, h)), figsize controls the entire figure canvas, not each individual subplot. Scale width with ncols and height with nrows so panels stay readable.

Pass layout="constrained" (available in Matplotlib 3.6+) to automatically prevent overlapping subplot titles and tick labels:

import numpy as np
import matplotlib.pyplot as plt
 
x = np.linspace(0, 2 * np.pi, 200)
fig, axes = plt.subplots(1, 3, figsize=(14, 4), layout="constrained")
 
axes[0].plot(x, np.sin(x))
axes[0].set_title("sin(x)")
 
axes[1].plot(x, np.cos(x), color="tab:orange")
axes[1].set_title("cos(x)")
 
axes[2].plot(x, np.sin(x) * np.cos(x), color="tab:green")
axes[2].set_title("sin(x) cos(x)")
 
plt.show()

Once you know the overall figure size, use the subplot layout generator to divide that space between panels using width and height ratios.

Resize an Existing Figure with set_size_inches()

If a library or helper function already created the figure, grab it with plt.gcf() (or keep your fig reference) and call set_size_inches():

import matplotlib.pyplot as plt
 
plt.plot([1, 2, 3, 4], [4, 2, 7, 5])
 
fig = plt.gcf()
fig.set_size_inches(11, 5, forward=True)
fig.savefig("resized_figure.png", dpi=150)

Setting forward=True updates interactive GUI windows immediately in addition to the figure object.

Set Global Default figsize with rcParams

To apply one consistent figure size across an entire script or Jupyter notebook, update plt.rcParams["figure.figsize"]:

import matplotlib.pyplot as plt
 
# Apply to all subsequent figures
plt.rcParams["figure.figsize"] = (10, 5)
plt.rcParams["figure.dpi"] = 120

You can also set the same option with matplotlib.rc():

import matplotlib
 
matplotlib.rc("figure", figsize=(10, 5), dpi=120)

To override figsize temporarily for a single block without mutating global state, use plt.rc_context():

with plt.rc_context({"figure.figsize": (12, 3)}):
    fig, ax = plt.subplots()
    ax.plot([1, 2, 3], [3, 1, 4])

To restore Matplotlib's built-in (6.4, 4.8) default at any point:

plt.rcParams["figure.figsize"] = plt.rcParamsDefault["figure.figsize"]

Save at Exact Resolution with savefig(dpi=...)

By default, fig.savefig() uses rcParams["savefig.dpi"] (which defaults to "figure", matching the figure's own DPI). Pass dpi= explicitly when exporting high-resolution assets for slides or print:

fig, ax = plt.subplots(figsize=(8, 4.5), layout="constrained")
ax.plot([1, 2, 3, 4], [1, 4, 2, 5])
fig.savefig("report_chart.png", dpi=300)

Watch out for bbox_inches="tight": while it prevents clipped axis labels, it crops or expands the canvas around artists, so the saved image will no longer match width_in × dpi pixels exactly. When you need exact pixel dimensions and unclipped labels, keep layout="constrained" and omit bbox_inches="tight". For more label-clipping fixes, see Matplotlib savefig Cuts Off Labels.

Control figsize in Pandas and Seaborn Plots

Pandas forwards figsize=(width, height) directly to Matplotlib:

import pandas as pd
 
df = pd.DataFrame({"revenue": [120, 145, 160, 195]}, index=["Q1", "Q2", "Q3", "Q4"])
ax = df.plot(kind="bar", figsize=(9, 4.5), title="Quarterly Revenue")

For multi-series layouts or Seaborn axes-level functions (sns.scatterplot, sns.boxplot, sns.heatmap), create the Matplotlib figure first and pass ax=:

import matplotlib.pyplot as plt
import seaborn as sns
 
fig, ax = plt.subplots(figsize=(9, 4.5))
sns.barplot(x=df.index, y=df["revenue"], ax=ax)

Note that Seaborn figure-level functions (sns.relplot, sns.displot, sns.catplot, sns.lmplot) ignore figsize=—control their size with height= (inches per row) and aspect= (width / height per facet) instead.

Common figsize Pitfalls and How to Fix Them

1. Calling plt.figure(figsize=...) after plt.plot()

plt.figure() always opens a new figure. Calling it after plt.plot() leaves the first plot at the default (6.4, 4.8) and creates a second empty figure at your requested size.

# Wrong: creates a default-size plot, then an empty (10, 4) figure
# plt.plot(x, y)
# plt.figure(figsize=(10, 4))
 
# Right: set figsize BEFORE plotting (or use fig, ax = plt.subplots(figsize=(10, 4)))
plt.figure(figsize=(10, 4))
plt.plot([1, 2, 3], [2, 4, 3])

2. Jupyter Notebook Display Looks Different From Saved Size

IPython's %matplotlib inline backend applies bbox_inches="tight" automatically and scales figures on Retina/HiDPI displays, so notebook previews can look cropped or smaller than your exported PNG. To inspect true canvas margins inside Jupyter, disable inline tight cropping:

%config InlineBackend.print_figure_kwargs = {'bbox_inches': None}

3. Text Looks Tiny After Increasing figsize

Font sizes in Matplotlib are measured in physical points (1 pt = 1/72 inch), not as a percentage of figure width. Doubling figsize from (6, 4) to (12, 8) makes 10pt axis labels look half as large relative to the chart. Keep figsize close to the final display size and increase dpi for sharper pixels instead of inflating figsize to (24, 16).

4. Overlapping Subplot Labels

When increasing subplot count without expanding figsize, tick labels collide. Increase figsize proportionally to (nrows, ncols) and pass layout="constrained" to plt.subplots().

FAQ

What units does Matplotlib figsize use?

Matplotlib figsize=(width, height) is always specified in inches. Multiply by dpi to get pixel dimensions (pixels = inches × dpi), or divide centimeters by 2.54 to convert metric sizes to inches.

What is the default figure size in Matplotlib?

The default rcParams["figure.figsize"] is [6.4, 4.8] inches and rcParams["figure.dpi"] is 100, producing a 640 × 480 pixel figure.

How do I change the figure size in Matplotlib without recreating the plot?

Call fig.set_size_inches(width, height, forward=True) on the figure object (or plt.gcf().set_size_inches(width, height) if you used the pyplot interface).

Why does figsize not work with sns.displot or sns.catplot?

Seaborn figure-level functions create their own FacetGrid instead of accepting plt.figure(figsize=...). Set their size with height (in inches) and aspect (width / height), or use axes-level functions (sns.histplot, sns.boxplot) with fig, ax = plt.subplots(figsize=(w, h)).

Related Guides