Skip to content

Commit c5ad0a4

Browse files
committed
Fix Area(fill=False)
1 parent 0db68f1 commit c5ad0a4

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

seaborn/_marks/area.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ def _plot(self, split_gen, scales, orient):
3131
verts = self._get_verts(data, orient)
3232
ax.update_datalim(verts)
3333

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

37-
kws["facecolor"] = resolve_color(self, keys, "", scales)
39+
kws["facecolor"] = fc
3840
kws["edgecolor"] = resolve_color(self, keys, "edge", scales)
3941
kws["linewidth"] = resolved["edgewidth"]
4042
kws["linestyle"] = resolved["edgestyle"]
4143

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

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

75+
fc = resolve_color(self, keys, "", scales)
76+
if not resolved["fill"]:
77+
fc = mpl.colors.to_rgba(fc, 0)
78+
7579
return mpl.patches.Patch(
76-
facecolor=resolve_color(self, keys, "", scales),
80+
facecolor=fc,
7781
edgecolor=resolve_color(self, keys, "edge", scales),
7882
linewidth=resolved["edgewidth"],
7983
linestyle=resolved["edgestyle"],

tests/_marks/test_area.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ def test_mapped(self):
8686
lws = [p.get_linewidth() for p in ax.patches]
8787
assert lws[0] > lws[1]
8888

89+
def test_unfilled(self):
90+
91+
x, y = [1, 2, 3], [1, 2, 1]
92+
p = Plot(x=x, y=y).add(Area(fill=False)).plot()
93+
ax = p._figure.axes[0]
94+
poly = ax.patches[0]
95+
assert poly.get_facecolor() == to_rgba("C0", 0)
96+
8997
def test_ribbon(self):
9098

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

0 commit comments

Comments
 (0)