From 7e1e03fe0ef46b844df37e12cfcc2aa6d0150d6a Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Sat, 23 May 2020 18:08:09 -0400 Subject: [PATCH 1/2] Improve lineplot handling of mpl kwargs Fixes #1526 --- seaborn/relational.py | 13 ++++++++----- seaborn/tests/test_relational.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/seaborn/relational.py b/seaborn/relational.py index a1b2677254..3fb5e80009 100644 --- a/seaborn/relational.py +++ b/seaborn/relational.py @@ -299,7 +299,8 @@ def plot(self, ax, kws): orig_linewidth = kws.pop("linewidth", kws.pop("lw", scout.get_linewidth())) - orig_dashes = kws.pop("dashes", "") + # Note that scout.get_linestyle() is` not correct as of mpl 3.2 + orig_linestyle = kws.pop("linestyle", kws.pop("ls", None)) kws.setdefault("markeredgewidth", kws.pop("mew", .75)) kws.setdefault("markeredgecolor", kws.pop("mec", "w")) @@ -319,9 +320,9 @@ def plot(self, ax, kws): # Set the default artist keywords kws.update(dict( color=orig_color, - dashes=orig_dashes, marker=orig_marker, - linewidth=orig_linewidth + linewidth=orig_linewidth, + linestyle=orig_linestyle, )) # Loop over the semantic subsets and draw a line for each @@ -345,8 +346,10 @@ def plot(self, ax, kws): kws["linewidth"] = self._size_map(size) if style is not None: attributes = self._style_map(style) - kws["dashes"] = attributes.get("dashes", orig_dashes) - kws["marker"] = attributes.get("marker", orig_marker) + if "dashes" in attributes: + kws["dashes"] = attributes["dashes"] + if "marker" in attributes: + kws["marker"] = attributes["marker"] line, = ax.plot([], [], **kws) line_color = line.get_color() diff --git a/seaborn/tests/test_relational.py b/seaborn/tests/test_relational.py index 016cc77d85..233700bf69 100644 --- a/seaborn/tests/test_relational.py +++ b/seaborn/tests/test_relational.py @@ -1435,6 +1435,22 @@ def test_axis_labels(self, long_df): assert ax2.get_ylabel() == "y" assert not ax2.yaxis.label.get_visible() + def test_matplotlib_kwargs(self, long_df): + + kws = { + "linestyle": "--", + "linewidth": 3, + "color": (1, .5, .2), + "markeredgecolor": (.2, .5, .2), + "markeredgewidth": 1, + } + ax = lineplot(data=long_df, x="x", y="y", **kws) + + line, *_ = ax.lines + for key, val in kws.items(): + plot_val = getattr(line, f"get_{key}")() + assert plot_val == val + def test_lineplot_axes(self, wide_df): f1, ax1 = plt.subplots() From e5b68123153b09e0f473b888dad2d4a699c99dcd Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Sat, 23 May 2020 18:09:37 -0400 Subject: [PATCH 2/2] Update release notes [ci skip] --- doc/releases/v0.11.0.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/releases/v0.11.0.txt b/doc/releases/v0.11.0.txt index 7948c51ed9..30e5301d76 100644 --- a/doc/releases/v0.11.0.txt +++ b/doc/releases/v0.11.0.txt @@ -24,6 +24,8 @@ v0.11.0 (Unreleased) - Improved :meth:`FacetGrid.set_titles` with `margin titles=True`, such that texts representing the original row titles are removed before adding new ones. GH2083 +- Fixed a bug where :func:`lineplot` did not pass the ``linestyle`` parameter down to matplotlib. GH2095 + - Changed how functions that use different representations for numeric and categorical data handle vectors with an `object` data type. Previously, data was considered numeric if it could be coerced to a float representation without error. Now, object-typed vectors are considered numeric only when their contents are themselves numeric. As a consequence, numbers that are encoded as strings will now be treated as categorical data. GH2084 - Improved the error messages produced when categorical plots process the orientation parameter.