Skip to content

[Bug]: fill_between with get_xaxis_transform increases y-limits #30320

Closed

Description

@metachow

Bug summary

In matplotlib 3.10.0, using fill_between() with transform=ax.get_xaxis_transform() increases the y-limits every time it is called, and the original plot gets squeezed gradually, which did not happen in previous version (3.8.0).

Code for reproduction

#Modified from https://matplotlib.org/stable/gallery/lines_bars_and_markers/fill_between_demo.html
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
x = np.arange(0, 4 * np.pi, 0.01)
y = np.sin(x)
ax.plot(x, y, color='black')

threshold = 0.75
ax.axhline(threshold, color='green', lw=2, alpha=0.7)
for i in range(10):
    ax.fill_between(x + 0.5*i, 0, 1, where=y > threshold, color='green', alpha=0.1, transform=ax.get_xaxis_transform())

Actual outcome

Image

Expected outcome

Image

Additional information

The expected outcome is from version 3.8.0

Operating system

Window 11

Matplotlib Version

3.10.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.12.11

Jupyter version

7.4.4

Installation

None

Activity

  1. changed the title [-][Bug]: fill_between with get_xaxis_transform increases y-limits[/-] [+][Bug]: `fill_between` with `get_xaxis_transform` increases y-limits[/+] on Jul 16, 2025
  2. timhoffm commented on Jul 16, 2025

    @timhoffm
    Member

    I suspect this part of #30287 #28702 may be the cause

    Image
  3. nrnavaneet commented on Jul 16, 2025

    @nrnavaneet
    Contributor

    Hi @timhoffm,

    I’d like to help fix this issue.

    Please let me know if there’s a preferred way to proceed or if I should start drafting a PR with a test case reproducing the problem.

  4. QuLogic commented on Jul 17, 2025

    @QuLogic
    Member

    I suspect this part of #30287 may be the cause

    This seems unrelated; which PR did you mean?

  5. timhoffm commented on Jul 17, 2025

    @timhoffm
    Member

    Sorry, wrong number. Sometimes GitHub autocompletion does strage things. The correct PR is #28702.

  6. added a commit that references this issue on Jul 17, 2025
    8e3b856
  7. timhoffm commented on Jul 17, 2025

    @timhoffm
    Member

    @nrnavaneet thanks for the interest in helping. However, here it was quicker for me to just write the fix instead of explaining what would need to be done.

  8. nrnavaneet commented on Jul 17, 2025

    @nrnavaneet
    Contributor

    Oh that's alright. 😄

  9. added 2 commits that reference this issue on Jul 20, 2025
    dd96cfe
    ef3faf2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions