Repository navigation
Description
Bug summary
Hi,
I am trying to save a plot to PDF (or SVG) that uses the fill_between function between two time series, and the resulting file is much larger than when plotting each series individually.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(seed=424242)
t_max = int(1e5)
t = np.arange(1, t_max+1, dtype=int)
data = rng.normal(size=(10, t_max))
# Lightweight figure (266 kb)
plt.figure(dpi=200)
plt.plot(t, np.min(data, axis=0), color='tab:blue', alpha=0.75)
plt.plot(t, np.max(data, axis=0), color='tab:blue', alpha=0.75)
plt.xlim(1, t_max)
plt.savefig(f"plot_minmax_{t_max}.svg")
# Large figure (1.1 Mb)
plt.figure(dpi=200)
plt.fill_between(t, np.min(data, axis=0), np.max(data, axis=0), color='tab:blue', alpha=0.5)
plt.xlim(1, t_max)
plt.savefig(f"plot_fill_{t_max}.svg")Actual outcome
Expected outcome
The file size of the file drawn with fill_between() should stay roughly the same as the file drawing the min and the max only.
Additional information
I have plotted the resulting file sizes for different numbers of data points.
The file size of the file generated with fill_between() grows linearly with the number of data points (as could be expected), but not the file size of the file plotting the min and the max directly: maybe there's an optimization in plot() that's not being used in fill_between() ?

Operating system
macOS
Matplotlib Version
3.4.3
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
Python 3.9.7
Jupyter version
No response
Installation
pip
Activity
jklymak commentedon Apr 8, 2022
Yes,
Line2Dstarts subsampling un-resolved data. https://matplotlib.org/stable/users/explain/performance.html#line-segment-simplification. OTOH, I don't see this rcParam mentioned at all in the docstring for Line2D, nor in the docstring forplot, which is a pretty big oversight in my opinion. Labelling as a documentation issue and good first issue, as it just requires mentioning the rcParams and linking to the explanation.tgrohens commentedon Apr 8, 2022
Thanks for the additional information!
From looking at the performance page and the code of
fill_between, the function generates a polygon, so I understand the line segments it comprises should be simplified as well?jklymak commentedon Apr 8, 2022
I don't think so - Polygons derive from Patch and do not have the Path logic in them.
tgrohens commentedon Apr 8, 2022
Ah, I see; in this case, maybe the documentation should be updated to reflect that?
It currently states (emphasis mine):
jklymak commentedon Apr 8, 2022
Maybe? I could be wrong, but I don't think it applies to polygons.
tgrohens commentedon Apr 8, 2022
Do you mean the outline of a polygon is different than a polygon?
In this case, my bad!
jklymak commentedon Apr 8, 2022
Well there are "polygons" and then there are instances of the
Polygonclass. I am pretty sure instances of thePolygonclass cannot simplify. I agree that the docs shouldn't make it sound likePolygonswill simplify, and that may have just been a mistake?tacaswell commentedon Apr 9, 2022
I agree with Jody, I think in that prose we are using "polygon" in the colloquial sense (in that we all look at the screen and agree it is "the outline of a ploygon") rather than a claim "that is a
Polygoninstance that is rendering the (thing we look at and call a polygon in english) on the screen".It is probably worth looking into if we do not use the path simplifiaction logic in drawing patches because we can not (at least with clipping there are good reasons we can not clip filled shapes) or because no one has tried to write the code to use the simplification logic.
I think the steps here are:
I'm going to label this a good first issue as it should involve no new API design (public API has to stay the same, we already have the path simplification code used else where in the code base, use the same rcparams), but medium difficulty because it will require reading and understanding where we do the path simplification in Line2D and than adapting it for use in
Patch(or its subclasses)Nishantppanchal commentedon Apr 10, 2022
Hey @tacaswell, could I be assigned to this issue? I am a first-year computer science student looking to take on a project to gain so experience and for fun of course. Just note, It may take me a bit of time however as I have to balance with uni.
jklymak commentedon Apr 10, 2022
@Nishantppanchal We do not assign or reserve issues. Thanks for your understanding.
Nishantppanchal commentedon Apr 10, 2022
@jklymak No problem.
wannieman98 commentedon Apr 28, 2022
Hi, I wanted to give this issue a try but wanted to clarify the tasks. My understanding with the comment @tacaswell has written. Is this simply a documentation issue or should the implementation of the simplification logic completed as well?
20 remaining items
tacaswell commentedon Oct 7, 2025
Yes, feel free to work on this issue.
tacaswell commentedon Nov 19, 2025
@cinocefalia Please see #22803 (comment) for the broad path of work here. I would add the additional first step of summarizing all of @tgrohens 's comments into a single post.
gigoiy commentedon Dec 9, 2025
Thank you @cinocefalia for the summarization of the thread for newcomers. I'll happily take this issue if it's still in limbo with no PR or contributors actively working on it. I'm starting work on it now. Actually, just read through the whole summary, is this issue about to be resolved?
gigoiy commentedon Dec 12, 2025
@cinocefalia I actually picked up a different issue that I've been working on, but I may try and tackle this one afterwards
feat: add path simplification support to Collections and enable it fo…
Silvio-Re commentedon Feb 27, 2026
Hello,
Thank you very much cinocefalia for providing a fix.
As I needed it now (some publication plots and the resulting files were really heavy), I made an AI make a monkey patch, and as it seems to work, I feel like I had to share if others need it now.
The test is made by hand and also tested on other plots. Not tested on pdf.
Below the "after.svg" (175.8 Kio), whereas the "before.svg" is 4.8 Mio and nearly identical (I will not upload it here, enough wasted resources for today).
Code
saitejaponnam12 commentedon Mar 23, 2026
Hi, I'd like to work on this issue.
I can start by reproducing the problem and investigating a possible fix.
Please let me know if it's available.
saitejaponnam12 commentedon Mar 25, 2026
Thanks for the feedback and discussion.
I noticed there are ongoing PRs (#31354, #31359) addressing similar path simplification
for
fill_betweenin the vector backends.If those approaches are preferred, I’m happy to step back or adjust this PR accordingly.
This was a useful exploration for me to understand how collections and path simplification
work in Matplotlib.
Please let me know if there’s a related follow-up or smaller improvement I could work on.
saitejaponnam12 commentedon Mar 26, 2026
Thanks for the clarification!
Glad to hear the approach looks less intrusive. I'll continue refining the solution and ensure it passes the full checks. Let me know if you'd like me to adjust anything specific.
Abhijeet-Kanungo commentedon Mar 29, 2026
Hi! I am a 3rd-year Mechanical Engineering student from OUTR Bhubaneswar, and I am currently drafting a GSoC 2026 proposal to enhance mplot3d. I would like to work on this issue to familiarize myself with the 3D axis rendering logic. Is it okay if I take this up?