From a792e9a132516cf92214b21f683cda02d5e11854 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Mon, 18 Sep 2023 09:47:27 -0400 Subject: [PATCH] Normalize matplotlib kwargs in scatterplot / lineplot --- seaborn/relational.py | 8 ++++++-- tests/test_relational.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/seaborn/relational.py b/seaborn/relational.py index c04188a7e9..d4ade9d46a 100644 --- a/seaborn/relational.py +++ b/seaborn/relational.py @@ -14,6 +14,7 @@ _default_color, _deprecate_ci, _get_transform_functions, + _normalize_kwargs, _scatter_legend_artist, ) from ._statistics import EstimateAggregator @@ -236,8 +237,9 @@ def plot(self, ax, kws): # gotten from the corresponding matplotlib function, and calling the # function will advance the axes property cycle. - kws.setdefault("markeredgewidth", kws.pop("mew", .75)) - kws.setdefault("markeredgecolor", kws.pop("mec", "w")) + kws = _normalize_kwargs(kws, mpl.lines.Line2D) + kws.setdefault("markeredgewidth", 0.75) + kws.setdefault("markeredgecolor", "w") # Set default error kwargs err_kws = self.err_kws.copy() @@ -397,6 +399,8 @@ def plot(self, ax, kws): if data.empty: return + kws = _normalize_kwargs(kws, mpl.collections.PathCollection) + # Define the vectors of x and y positions empty = np.full(len(data), np.nan) x = data.get("x", empty) diff --git a/tests/test_relational.py b/tests/test_relational.py index 569798a785..4c7ff43ee9 100644 --- a/tests/test_relational.py +++ b/tests/test_relational.py @@ -1732,6 +1732,12 @@ def test_unfilled_marker_edgecolor_warning(self, long_df): # GH2636 warnings.simplefilter("error") scatterplot(data=long_df, x="x", y="y", marker="+") + def test_short_form_kwargs(self, long_df): + + ax = scatterplot(data=long_df, x="x", y="y", ec="g") + pts = ax.collections[0] + assert same_color(pts.get_edgecolors().squeeze(), "g") + def test_scatterplot_vs_relplot(self, long_df, long_semantics): ax = scatterplot(data=long_df, **long_semantics)