Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve lineplot handling of mpl kwargs #2095

Merged
merged 2 commits into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/releases/v0.11.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions seaborn/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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
Expand All @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions seaborn/tests/test_relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down