Skip to content

Commit

Permalink
Fix Area(fill=False)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Jul 12, 2022
1 parent 0db68f1 commit c5ad0a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 10 additions & 6 deletions seaborn/_marks/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def _plot(self, split_gen, scales, orient):
verts = self._get_verts(data, orient)
ax.update_datalim(verts)

# TODO fill= is not working here properly
# We could hack a fix, but would be better to handle fill in resolve_color
# TODO should really move this logic into resolve_color
fc = resolve_color(self, keys, "", scales)
if not resolved["fill"]:
fc = mpl.colors.to_rgba(fc, 0)

kws["facecolor"] = resolve_color(self, keys, "", scales)
kws["facecolor"] = fc
kws["edgecolor"] = resolve_color(self, keys, "edge", scales)
kws["linewidth"] = resolved["edgewidth"]
kws["linestyle"] = resolved["edgestyle"]

# path = mpl.path.Path(verts) # TODO, closed=True)
# patches[ax].append(mpl.patches.PathPatch(path, **kws))
patches[ax].append(mpl.patches.Polygon(verts, **kws))

for ax, ax_patches in patches.items():
Expand Down Expand Up @@ -72,8 +72,12 @@ def _legend_artist(self, variables, value, scales):
keys = {v: value for v in variables}
resolved = resolve_properties(self, keys, scales)

fc = resolve_color(self, keys, "", scales)
if not resolved["fill"]:
fc = mpl.colors.to_rgba(fc, 0)

return mpl.patches.Patch(
facecolor=resolve_color(self, keys, "", scales),
facecolor=fc,
edgecolor=resolve_color(self, keys, "edge", scales),
linewidth=resolved["edgewidth"],
linestyle=resolved["edgestyle"],
Expand Down
8 changes: 8 additions & 0 deletions tests/_marks/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ def test_mapped(self):
lws = [p.get_linewidth() for p in ax.patches]
assert lws[0] > lws[1]

def test_unfilled(self):

x, y = [1, 2, 3], [1, 2, 1]
p = Plot(x=x, y=y).add(Area(fill=False)).plot()
ax = p._figure.axes[0]
poly = ax.patches[0]
assert poly.get_facecolor() == to_rgba("C0", 0)

def test_ribbon(self):

x, ymin, ymax = [1, 2, 4], [2, 1, 4], [3, 3, 5]
Expand Down

0 comments on commit c5ad0a4

Please sign in to comment.