Skip to content

Enable path simplification for FillBetweenPolyCollection to reduce vector output size#31361

Open
saitejaponnam12 wants to merge 2 commits intomatplotlib:mainfrom
saitejaponnam12:fix-fill-between-simplify
Open

Enable path simplification for FillBetweenPolyCollection to reduce vector output size#31361
saitejaponnam12 wants to merge 2 commits intomatplotlib:mainfrom
saitejaponnam12:fix-fill-between-simplify

Conversation

@saitejaponnam12
Copy link

@saitejaponnam12 saitejaponnam12 commented Mar 24, 2026

Closes #22803

PR summary

This patch enables path simplification for FillBetweenPolyCollection.

Currently, Axes.fill_between generates dense closed polygons (≈2N vertices), which leads to very large SVG/PDF outputs.
Although Matplotlib has path simplification support, collection templates in vector backends bypass it.

This change marks paths created by FillBetweenPolyCollection with should_simplify=True, allowing existing simplification logic to reduce redundant vertices when saving vector graphics.

Why is this change necessary?

Vector outputs created using fill_between can become excessively large due to dense polygon paths. This makes files slow to render and inefficient to store.

What problem does it solve?

Enables simplification of fill_between polygons, significantly reducing SVG/PDF file sizes.

Implementation reasoning

  • Uses existing Path.should_simplify mechanism
  • Targets only FillBetweenPolyCollection
  • No API changes
  • Minimal and safe modification

This is a focused change that leverages existing infrastructure without altering default behavior for other collections.

AI Disclosure

I used AI assistance for understanding the codebase structure and drafting the initial implementation idea. The final code change and testing decisions were reviewed and validated manually.

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue (N/A)
  • new and changed code is tested (manual validation of behavior)
  • Plotting related features demonstrated in example (N/A)
  • New Features and API Changes noted (N/A)
  • Documentation complies with guidelines (N/A)

Copilot AI review requested due to automatic review settings March 24, 2026 05:17
@github-actions
Copy link

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 gitter 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.

@saitejaponnam12
Copy link
Author

Thanks for reviewing! Please let me know if any additional tests, benchmarks, or documentation updates would be helpful. I'm happy to iterate on this PR.

This comment was marked as spam.

@melissawm melissawm moved this to Needs review in First Time Contributors Mar 25, 2026
@melissawm
Copy link
Member

You may need to rebase on main to fix the docs failure - it's unrelated to this PR.

@WeatherGod
Copy link
Member

As a general rule, we don't automatically simplify vector outputs because we can't know the resolution of the end-user's renderer. matplotlib's builtin path simplification algorithm partly depends on that knowledge to produce output that should render identically with or without it.

@WeatherGod
Copy link
Member

Note, I'm not against making this possible, just that it probably should not be by default for vector backends. Not exactly sure how that would look, though.

@saitejaponnam12
Copy link
Author

Thanks for the feedback!

You're right enabling simplification by default for vector backends may change output depending on renderer resolution.

Instead of forcing it, I can modify the implementation to:

  • Respect existing rcParams["path.simplify"]
  • Only apply simplification when explicitly enabled
  • Keep current default behaviour unchanged

This would make the change opt-in and avoid altering existing rendering results.

Would this approach be preferable?

@rcomer
Copy link
Member

rcomer commented Mar 25, 2026

I assume this is aiming to address #22803. If so, please link it in the PR description.

@melissawm melissawm moved this from Needs review to Waiting for author in First Time Contributors Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Waiting for author

Development

Successfully merging this pull request may close these issues.

[Bug]: Large file size when using fill_between()

5 participants