GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Skip hidden y-axis offset text when positioning titles (fix #31881) by binggao1230 · Pull Request #31885 · matplotlib/matplotlib

Conversation

@binggao1230

@binggao1230 binggao1230 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

PR summary

Fixes #31881 — plt.subplots(1, 2, sharey=True, tight_layout=True) with per-subplot titles and large y-values raised ValueError: cannot convert float NaN to integer on draw. Regression in 3.11.0, bisected by @ksunden to #31285.

Root cause

On the inner subplot the y axis is shared, so its offset text is hidden (set_visible(False)) but still carries text (e.g. '1e53'). Axes._update_title_position decides whether to lift the title above the offset text by checking only offsetText.get_text(), not its visibility:

if ax.yaxis.offsetText.get_text():
    bb = ax.yaxis.offsetText.get_tightbbox(renderer)
    if bb.intersection(title.get_tightbbox(renderer), bb):
        top = bb.ymax

Since #31285, Text.get_tightbbox returns Bbox.null() for hidden/empty text. Bbox.null() is [[inf, inf], [-inf, -inf]], which has xmin=-inf, xmax=+inf — so it behaves as an infinite box under intersection, making the guard pass and setting top = bb.ymax = inf. The title is then placed at y = inf; its window extent feeds tight_layout, which computes a NaN subplot position, and the subsequent YAxis.get_tick_space does int(np.floor(NaN)) → the error.

Fix

A hidden offset text is not drawn, so it should not influence the title position. Only consider it when it is visible. This also fixes the (silently broken) title placement that occurs without tight_layout — the title was being moved to infinity there too, just without a downstream crash.

Test

test_title_above_hidden_offset reproduces the issue and asserts the title and subplot positions stay finite. It fails on main (raises the original ValueError) and passes with the fix. The existing test_title_above_offset covers the visible-offset case, which is unchanged.

I verified the change against an installed 3.11.0 build by patching the single edited file (the change is pure-Python).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@binggao1230
Skip hidden offset text when positioning Axes titles
80b56f9
The y-axis offset text of an inner subplot that shares its y axis is
hidden but still carries text. _update_title_position only checked
get_text(), so since matplotlib#31285 (which makes a hidden text report a null,
non-finite tight bbox) the offset text pushed the title -- and the
subplot position computed by tight_layout -- to inf/NaN. Drawing then
raised "cannot convert float NaN to integer".

Only consider the offset text for title placement when it is visible.
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the first-contribution label Jun 12, 2026
@github-project-automation github-project-automation Bot added this to First Time Contributors Jun 12, 2026
@github-actions github-actions Bot added the topic: axes label Jun 12, 2026
@binggao1230

binggao1230 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the welcome! To answer the AI question directly: yes, this PR was written with AI assistance (Claude), working under my direction and review.

I drove the debugging — reproducing the crash headlessly, bisecting it to #31285, and tracing the NaN back through tight_layout to _update_title_position, where a hidden y-axis offset text still contributed its (now non-finite) Bbox.null() tight bbox and pushed the title to infinity. I verified the fix and the regression test myself (red on main, green with the change) by patching the single edited pure-Python file over an installed 3.11 build.

Happy to adjust the approach, comment, or test if you'd prefer a different fix location (e.g. guarding the bbox itself rather than the visibility check).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@binggao1230

binggao1230 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

Note on CI: the one red job (Azure Main Pytest Windows_py313) failed on test_agg_filter_alpha[gif] with an ImageMagick _ConverterError — magick.exe: improper image header ... agg_filter_alpha-expected.gif while converting the baseline GIF. That's a test-infrastructure/image-conversion issue on the Windows runner, unrelated to this change (which only touches title positioning). All 8878 other tests pass on that job, and the full GitHub Actions matrix is green. Happy to rebase if a re-run is wanted.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

timhoffm
timhoffm approved these changes Jun 13, 2026
View reviewed changes
rcomer
rcomer approved these changes Jun 14, 2026
View reviewed changes
@rcomer rcomer added this to the v3.11.1 milestone Jun 14, 2026
@rcomer
rcomer merged commit ea157d7 into matplotlib:main Jun 14, 2026
39 of 41 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-project-automation github-project-automation Bot moved this to Merged in First Time Contributors Jun 14, 2026
@meeseeksmachine meeseeksmachine mentioned this pull request Jun 14, 2026
Backport PR #31885 on branch v3.11.x (Skip hidden y-axis offset text when positioning titles (fix #31881)) #31893
Merged
@rcomer

rcomer commented Jun 14, 2026

Copy link
Copy Markdown
Member

Thanks for solving that so quickly @gaoflow and congratulations on your first Matplotlib PR 🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

QuLogic pushed a commit that referenced this pull request Jun 16, 2026
@rcomer @meeseeksmachine
Backport PR #31885: Skip hidden y-axis offset text when positioning t…
2f8b805
…itles (fix #31881)
QuLogic added a commit that referenced this pull request Jun 16, 2026
@QuLogic
Merge pull request #31893 from meeseeksmachine/auto-backport-of-pr-31…
f05f507
…885-on-v3.11.x

Backport PR #31885 on branch v3.11.x (Skip hidden y-axis offset text when positioning titles (fix #31881))
oldrobotdev added a commit to oldrobotdev/PyPSA that referenced this pull request Jul 2, 2026
@oldrobotdev
fix(plot): exclude matplotlib 3.11.0, which crashes faceted plots
e9fe056
Faceted statistics plots with a shared y-axis and scientific offset text
crash at draw time on matplotlib 3.11.0 with 'ValueError: cannot convert
float NaN to integer'. This is an upstream regression
(matplotlib/matplotlib#31881, bisected to matplotlib/matplotlib#31285)
fixed by matplotlib/matplotlib#31885 and milestoned for 3.11.1, which is
not released yet. Exclude the broken version and add a regression test
covering the offset-text faceting scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@timhoffm timhoffm timhoffm approved these changes
@rcomer rcomer rcomer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

first-contribution topic: axes

Projects

First Time Contributors
Status: Merged

Milestone

v3.11.1

Development

Successfully merging this pull request may close these issues.

[Bug]: ValueError ("cannot convert float NaN to integer") when trying to show horizontally-stacked subplots

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@binggao1230 @rcomer @timhoffm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.