Skip to content

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

@metachow

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions