Skip to content

Commit

Permalink
Normalize matplotlib kwargs in scatterplot / lineplot
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Sep 18, 2023
1 parent fbc44d5 commit a792e9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions seaborn/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
_default_color,
_deprecate_ci,
_get_transform_functions,
_normalize_kwargs,
_scatter_legend_artist,
)
from ._statistics import EstimateAggregator
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a792e9a

Please sign in to comment.