What do bbox_inches='tight' and transparent do in savefig, and when would you use them?

Quick Overview

Asks what the bbox_inches='tight' and transparent options do when saving a Matplotlib figure with savefig, and when each one is the right choice. Tests practical knowledge of clipped labels, output image size, file formats and how plots look on different backgrounds.

What do bbox_inches='tight' and transparent do in savefig, and when would you use them?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What do `bbox_inches='tight'` and `transparent` do in Matplotlib's `savefig`, and when would you use them? ```hint Picture the saved file Think about a legend placed outside the axes when the figure is saved at its default size, and about how the saved image looks when you drop it onto a dark slide. ``` ### What a Strong Answer Covers - What `bbox_inches='tight'` changes in the saved file, and how `pad_inches` relates to it - What `transparent=True` makes transparent and what it leaves unchanged - Situations where each option is the right choice - Caveats, such as changed output dimensions, file formats without an alpha channel, and readability on dark backgrounds ### Follow-up Questions - A figure looks right in a Jupyter notebook, but the saved PNG cuts off its legend. Why? - How would you produce a figure at an exact pixel size and still avoid clipped labels? - What happens if you save with `transparent=True` to a JPEG file? - How would you make a transparent figure readable on both light and dark backgrounds?

Overview: Asks what the bbox_inches='tight' and transparent options do when saving a Matplotlib figure with savefig, and when each one is the right choice. Tests practical knowledge of clipped labels, output image size, file formats and how plots look on different backgrounds.

General logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What do bbox_inches='tight' and transparent do in Matplotlib's savefig, and when would you use them?

What a Strong Answer Covers Guidance

  • What bbox_inches='tight' changes in the saved file, and how pad_inches relates to it
  • What transparent=True makes transparent and what it leaves unchanged
  • Situations where each option is the right choice
  • Caveats, such as changed output dimensions, file formats without an alpha channel, and readability on dark backgrounds

Follow-up Questions Guidance

  • A figure looks right in a Jupyter notebook, but the saved PNG cuts off its legend. Why?
  • How would you produce a figure at an exact pixel size and still avoid clipped labels?
  • What happens if you save with transparent=True to a JPEG file?
  • How would you make a transparent figure readable on both light and dark backgrounds?