imshow figure size
plot display issues
matplotlib customization
image visualization
figure resizing

figure of imshow is too small

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When an imshow plot looks too small, the image data is usually fine and the figure container is the real problem. In Matplotlib, the most direct fix is to create a larger figure with an explicit figsize, and sometimes to raise the DPI if the rendered result still looks cramped.

Why imshow Looks Small

imshow draws an image inside the current axes. If you do not control the figure size, Matplotlib uses its defaults, which can be too compact for large arrays, notebook output cells, or high-DPI displays.

This means there are two different concepts:

  • image resolution, which comes from the array shape
  • displayed figure size, which comes from figure settings

Changing one does not automatically change the other.

The Simplest Fix: Set figsize

Start by creating the figure yourself before calling imshow:

python
1import matplotlib.pyplot as plt
2import numpy as np
3
4image = np.random.rand(200, 300)
5
6plt.figure(figsize=(10, 6))
7plt.imshow(image, cmap="gray")
8plt.colorbar()
9plt.show()

The figsize values are measured in inches. A larger width and height give the image more room on screen and in saved output.

If you prefer the object-oriented style:

python
1import matplotlib.pyplot as plt
2import numpy as np
3
4image = np.random.rand(200, 300)
5
6fig, ax = plt.subplots(figsize=(10, 6))
7ax.imshow(image, cmap="viridis")
8ax.set_title("Larger imshow figure")
9plt.show()

That is often easier to manage in real projects.

DPI Affects Sharpness More Than Layout

Sometimes the figure is physically large enough, but it still looks blurry or too dense when saved. That is where DPI matters.

python
fig, ax = plt.subplots(figsize=(10, 6), dpi=150)
ax.imshow(image, cmap="magma")
plt.show()

Higher DPI increases pixel density in the rendered figure. It does not replace figsize, but it can make details more readable in exported images.

When saving:

python
fig.savefig("plot.png", dpi=200, bbox_inches="tight")

This is especially useful for reports or slides.

Notebook and Inline Display Issues

In Jupyter notebooks, plots may still appear small because the notebook frontend constrains their display area. You can raise the default figure size for the session:

python
1import matplotlib.pyplot as plt
2
3plt.rcParams["figure.figsize"] = (10, 6)
4plt.rcParams["figure.dpi"] = 120

After that, future plots inherit the larger defaults unless overridden.

If you only change the array size but not the figure size, the notebook may still render the plot into a small output box. That is why editing figsize is usually the first thing to try.

Aspect Ratio and Axes Choices

The figure may also look awkward if the aspect ratio does not match the image shape. imshow preserves aspect by default, which is often correct, but it can leave unused space or make one dimension feel cramped.

python
fig, ax = plt.subplots(figsize=(12, 4))
ax.imshow(image, aspect="auto")
plt.show()

Use aspect="auto" only when stretching is acceptable. For scientific or image-processing work, preserving the true pixel aspect is often more important than filling the available area.

Also consider removing unnecessary axes decorations if the image itself is what matters:

python
1fig, ax = plt.subplots(figsize=(8, 8))
2ax.imshow(image, cmap="gray")
3ax.axis("off")
4plt.show()

That gives more visual space to the data.

Common Pitfalls

One common mistake is calling plt.imshow first and then wondering why the defaults are too small. Set up the figure before plotting.

Another mistake is increasing DPI when the real issue is layout size. DPI affects detail and export sharpness, but figsize controls how much room the axes get.

It is also easy to overlook notebook-specific display limits. If a figure looks fine when saved but small inline, the frontend is likely constraining it.

Summary

  • 'imshow uses the current figure and axes size, so small output often means a small figure.'
  • Fix it first with plt.figure(figsize=(...)) or plt.subplots(figsize=(...)).
  • Use DPI to improve sharpness, especially when saving images.
  • Set rcParams in notebooks if many plots need larger defaults.
  • Adjust aspect and axes visibility only after the figure size is right.

Course illustration
Course illustration

All Rights Reserved.