Skip to content

Commit

Permalink
FIX: Artifacts in stackplot if height of input is zero
Browse files Browse the repository at this point in the history
closes #22393
  • Loading branch information
tlkaufmann authored and tacaswell committed Apr 30, 2022
1 parent 89b21b5 commit f47d057
Show file tree
Hide file tree
Showing 6 changed files with 812 additions and 14 deletions.
7 changes: 4 additions & 3 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2860,11 +2860,12 @@ def spy(
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.stackplot)
def stackplot(
x, *args, labels=(), colors=None, baseline='zero', data=None,
**kwargs):
x, *args, labels=(), colors=None, baseline='zero',
where=None, data=None, **kwargs):
return gca().stackplot(
x, *args, labels=labels, colors=colors, baseline=baseline,
**({"data": data} if data is not None else {}), **kwargs)
where=where, **({"data": data} if data is not None else {}),
**kwargs)


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
Expand Down
15 changes: 14 additions & 1 deletion lib/matplotlib/stackplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def stackplot(axes, x, *args,
labels=(), colors=None, baseline='zero',
labels=(), colors=None, baseline='zero', where=None,
**kwargs):
"""
Draw a stacked area plot.
Expand Down Expand Up @@ -56,6 +56,13 @@ def stackplot(axes, x, *args,
data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER
where: bool or array of bool, optional
Passed to `.Axes.fill_between` and defines where to exclude horizontal
regions from being filled. The filled regions are defined by the
coordinates `x[where]`. Can be either a single bool, an array of shape
(N,) or an array of shape (M, N).
Should be used together with `interpolate=True`.
**kwargs
All other keyword arguments are passed to `.Axes.fill_between`.
Expand All @@ -68,6 +75,10 @@ def stackplot(axes, x, *args,

y = np.row_stack(args)

if where is None:
where = True
where = np.broadcast_to(where, np.shape(y))

labels = iter(labels)
if colors is not None:
axes.set_prop_cycle(color=colors)
Expand Down Expand Up @@ -111,6 +122,7 @@ def stackplot(axes, x, *args,
color = axes._get_lines.get_next_color()
coll = axes.fill_between(x, first_line, stack[0, :],
facecolor=color, label=next(labels, None),
where=where[0, :],
**kwargs)
coll.sticky_edges.y[:] = [0]
r = [coll]
Expand All @@ -120,5 +132,6 @@ def stackplot(axes, x, *args,
color = axes._get_lines.get_next_color()
r.append(axes.fill_between(x, stack[i, :], stack[i + 1, :],
facecolor=color, label=next(labels, None),
where=where[i+1, :],
**kwargs))
return r
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f47d057

Please sign in to comment.