You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: stackplot creates artifacts when height of input is zero #22393
One can see thin grey lines where the red object hast zero height.
Expected outcome
The thin lines are gone
Additional information
This only happens when the color above and below the empty data has the same color, but there are some use-cases where this is needed (see e.g. fish plots for evolutionary relationships).
Fix
The individual calls to fill_between need to have the following parameters: where=(stack[i, :] != stack[i+1, :]), interpolate=True and edgecolor=color.
These are the changes made to matplotlib/lib/matplotlib/stackplot.py
# Color between x = 0 and the first array.color=ax._get_lines.get_next_color()
coll=ax.fill_between(x, 0, stack[0, :],
where=(stack[0, :] !=0), interpolate=True, edgecolor=color,
facecolor=color, label=next(labels, None), **kwargs)
coll.sticky_edges.y[:] = [0]
r= [coll]
# Color between array i-1 and array iforiinrange(len(y) -1):
color=ax._get_lines.get_next_color()
r.append(ax.fill_between(x, stack[i, :], stack[i+1, :],
where=(stack[i, :] !=stack[i+1, :]), interpolate=True, edgecolor=color,
facecolor=color, label=next(labels, None), **kwargs))
These changes get rid of the lines but as far as I tested it do not have side effects for other plots. Probably one should check whether edgecolor is set in **kwargs as well.
I guess its a question of whether you want the zero-width stack to show up at all or not. I understand why you want to remove it, but I'm not sure if that is what folks who do stackplots want in general? (BTW< I'm sure the line is there even if both sides aren't blue, it just may not be as noticeable).
Good point. I also don't know what the standard stackplot user would want. Would be easy to make a parameter like show_empty for stackplot? If it defaults to False, it won't break any current use-cases.
Either way, I don't think the current behavior is intended because the thin line prevails even if I set linewidth = 0. So we are not seeing the outline of the polygon but an artifact of the anti-aliasing. This can be shown as the thin line disappears when setting aa=False.
I agree its an anti aliasing artifact. I guess I'm mildly in favour of your change as fixing a display bug, unless there is some reason to fear it will be a lot slower. Did you want to open a PR?
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Carification of root cause: The underlying problem here is not drawing of a 0-range. You can test by hiding the red area in the above example (im[2].set_visible(False)), which does not change the plot.
Instead it is that we have two filled regions (the blue ones in the exmaple) with adjacent edges, and since these polygons are rendered individually there can be antialiasing effects on the edge so that there may be a visual border even though the edges are perfectly aligned.
I'm going to close this as won't fixt for the following reasons:
This is a fundamental rendering limitation that cannot be handled on our side. - It's the general problem of individual antialiased rendering two polygons that share an edge.
This will only be visible in stackplots if stack elements i and i+2 have the same color and element i has a 0-region. That should be quite an edge case.
Activity
jklymak commentedon Feb 4, 2022
I guess its a question of whether you want the zero-width stack to show up at all or not. I understand why you want to remove it, but I'm not sure if that is what folks who do stackplots want in general? (BTW< I'm sure the line is there even if both sides aren't blue, it just may not be as noticeable).
tlkaufmann commentedon Feb 4, 2022
Good point. I also don't know what the standard stackplot user would want. Would be easy to make a parameter like
show_emptyforstackplot? If it defaults to False, it won't break any current use-cases.Either way, I don't think the current behavior is intended because the thin line prevails even if I set
linewidth = 0. So we are not seeing the outline of the polygon but an artifact of the anti-aliasing. This can be shown as the thin line disappears when settingaa=False.jklymak commentedon Feb 4, 2022
I agree its an anti aliasing artifact. I guess I'm mildly in favour of your change as fixing a display bug, unless there is some reason to fear it will be a lot slower. Did you want to open a PR?
Bugfix for issue matplotlib#22393: Artifacts in stackplot if height o…
tlkaufmann commentedon Feb 7, 2022
I opened a PR for this issue incorporating the fix detailed above: #22424
Thanks for your help @jklymak
jklymak commentedon Feb 7, 2022
Let's leave open until the pr is in. Thanks.
New approach for issue matplotlib#22393: Give parameter `where` to st…
FIX: Artifacts in stackplot if height of input is zero
FIX: Artifacts in stackplot if height of input is zero
github-actions commentedon Nov 24, 2025
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
timhoffm commentedon Dec 7, 2025
Carification of root cause: The underlying problem here is not drawing of a 0-range. You can test by hiding the red area in the above example (
im[2].set_visible(False)), which does not change the plot.Instead it is that we have two filled regions (the blue ones in the exmaple) with adjacent edges, and since these polygons are rendered individually there can be antialiasing effects on the edge so that there may be a visual border even though the edges are perfectly aligned.
I'm going to close this as won't fixt for the following reasons: