Skip to content

Commit

Permalink
Avoid matplotlib warning about edgecolor on an unfilled scatterplot m…
Browse files Browse the repository at this point in the history
…arker (#2636)

(cherry picked from commit c20d910)
  • Loading branch information
mwaskom committed Aug 8, 2021
1 parent 06827e2 commit 11e64bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion seaborn/relational.py
Expand Up @@ -632,7 +632,6 @@ def plot(self, ax, kws):

# Set defaults for other visual attributes
kws.setdefault("linewidth", .08 * np.sqrt(np.percentile(s, 10)))
kws.setdefault("edgecolor", "w")

if "style" in self.variables:
# Use a representative marker so scatter sets the edgecolor
Expand All @@ -642,6 +641,14 @@ def plot(self, ax, kws):
example_marker = self._style_map(example_level, "marker")
kws.setdefault("marker", example_marker)

# Conditionally set the marker edgecolor based on whether the marker is "filled"
# See https://github.com/matplotlib/matplotlib/issues/17849 for context
m = kws.get("marker", mpl.rcParams.get("marker", "o"))
if not isinstance(m, mpl.markers.MarkerStyle):
m = mpl.markers.MarkerStyle(m)
if m.is_filled():
kws.setdefault("edgecolor", "w")

# TODO this makes it impossible to vary alpha with hue which might
# otherwise be useful? Should we just pass None?
kws["alpha"] = 1 if self.alpha == "auto" else self.alpha
Expand Down
6 changes: 6 additions & 0 deletions seaborn/tests/test_relational.py
Expand Up @@ -1755,6 +1755,12 @@ def test_datetime_scale(self, long_df):
# https://github.com/matplotlib/matplotlib/issues/17586
ax.get_xlim()[0] > ax.xaxis.convert_units(np.datetime64("2002-01-01"))

def test_unfilled_marker_edgecolor_warning(self, long_df): # GH2636

with pytest.warns(None) as record:
scatterplot(data=long_df, x="x", y="y", marker="+")
assert not record

def test_scatterplot_vs_relplot(self, long_df, long_semantics):

ax = scatterplot(data=long_df, **long_semantics)
Expand Down

0 comments on commit 11e64bc

Please sign in to comment.