Skip to content

Simplify fill_between (#22803) - #31354

Closed
ghost wants to merge 20 commits into
mainfrom
unknown repository
Closed

ghost wants to merge 20 commits into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Mar 23, 2026

Copy link
Copy Markdown

PR summary

Suggestion for closing #22803

This PR improves fill_between() output size in the PDF and SVG backends when path simplification is enabled.

Why

plot() already benefits from path simplification because Line2D paths are passed to the backends with the relevant simplification behavior already in place. In contrast, fill_between() produces a FillBetweenPolyCollection, and the resulting collection paths were not consistently reaching the vector backends in a form that allowed the same simplification to happen.

In practice, this meant that increasing path.simplify_threshold greatly reduced vector output size for line plots, but often had little or no effect for fill_between().

What does this PR change

  • FillBetweenPolyCollection marks its generated paths as simplifiable.
  • PDF/SVG simplification is applied only to paths explicitly marked with should_simplify=True.
  • The PDF collection optimization logic is adjusted so simplifiable collection paths are not blocked from reaching the simplification path in common single-use cases.

Results

In the large-data case discussed in #22803, fill_between() PDF/SVG output size is reduced by ~98–99% when simplification is enabled, bringing it in line with the reductions already seen for line plots.

Testing

Regression test has been added in lib/matplotlib/tests/test_fill_between_simplify.py.

AI was used to assist with debugging environment issues and refining the PR description, all the rest being manually tested.

More detailed info on this approach can be found here: #22803 (comment)

cinocefalia added 20 commits November 15, 2025 16:45
…SVG while keeping PDF the same"

This reverts commit ab81ebf.
Fixes #22803.

- Simplify path handling in PDF/SVG backends
- Reduce output size for fill_between
- Add regression test
@ghost

ghost commented Mar 23, 2026

Copy link
Copy Markdown
Author

Closing in favor of a cleaned PR branch with only the intended commits/files.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants