Skip to content

Fix NonUniformImage tight bounding box when extent is omitted (#32707) - #32709

Open
QTSHI wants to merge 1 commit into
matplotlib:mainfrom
QTSHI:cursor/nonuniformimage-tight-extent-7867
Open

QTSHI wants to merge 1 commit into
matplotlib:mainfrom
QTSHI:cursor/nonuniformimage-tight-extent-7867

Conversation

@QTSHI

@QTSHI QTSHI commented Dec 3, 2026

Copy link
Copy Markdown

PR summary

Closes #32707

Saving a NonUniformImage with bbox_inches="tight" raised
TypeError: cannot unpack non-iterable NoneType object when no
extent was given. The same crash also showed up with tight_layout
and constrained layout. AxesImage.get_window_extent() unpacked
self._extent directly, and for a NonUniformImage that value stays
None after set_data unless the caller set an extent.

get_extent() already returns the grid bounds (x[0], x[-1], y[0], y[-1]).
get_window_extent() now uses the stored extent when one was set, and
calls get_extent() only when _extent is still None. An explicit
extent is left unchanged: NonUniformImage.get_extent() ignores
_extent and always reports the coordinate arrays, so calling
get_extent() unconditionally would have dropped a caller-supplied
extent. pcolorfast still passes an extent, so that path is the same.

AI Disclosure

This patch was prepared with assistance from GPT. I reviewed the
change and the new tests.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

…tlib#32707)

AxesImage.get_window_extent unpacked self._extent, which stays None
when NonUniformImage is constructed without an extent. Saving with
bbox_inches="tight", tight_layout, and constrained layout then raised
TypeError.

Keep an explicit extent when one was stored. Otherwise use get_extent(),
which already reports the coordinate-array bounds.
@QTSHI QTSHI closed this Dec 3, 2026
@QTSHI
QTSHI deleted the cursor/nonuniformimage-tight-extent-7867 branch December 3, 2026 02:43
@QTSHI
QTSHI restored the cursor/nonuniformimage-tight-extent-7867 branch December 3, 2026 02:46
@QTSHI QTSHI reopened this Dec 3, 2026
@rcomer rcomer added the AgentScan: automated AgentScan classified an account as automated. label Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AgentScan: automated AgentScan classified an account as automated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Saving a NonUniformImage with bbox_inches="tight" raises TypeError when extent is omitted

2 participants