Enable path simplification for FillBetweenPolyCollection to reduce vector output size#31361
Enable path simplification for FillBetweenPolyCollection to reduce vector output size#31361saitejaponnam12 wants to merge 2 commits intomatplotlib:mainfrom
Conversation
|
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. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
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. |
|
You may need to rebase on main to fix the docs failure - it's unrelated to this PR. |
|
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. |
|
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. |
|
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:
This would make the change opt-in and avoid altering existing rendering results. Would this approach be preferable? |
|
I assume this is aiming to address #22803. If so, please link it in the PR description. |
Closes #22803
PR summary
This patch enables path simplification for
FillBetweenPolyCollection.Currently,
Axes.fill_betweengenerates 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
FillBetweenPolyCollectionwithshould_simplify=True, allowing existing simplification logic to reduce redundant vertices when saving vector graphics.Why is this change necessary?
Vector outputs created using
fill_betweencan 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_betweenpolygons, significantly reducing SVG/PDF file sizes.Implementation reasoning
Path.should_simplifymechanismFillBetweenPolyCollectionThis 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