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

Use drawstyle instead of linestyle in plot.step. #3274

Merged
merged 1 commit into from
Mar 26, 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
7 changes: 6 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ v0.16.0 (unreleased)

Breaking changes
~~~~~~~~~~~~~~~~

- Alternate draw styles for :py:meth:`plot.step` must be passed using the
``drawstyle`` (or ``ds``) keyword argument, instead of the ``linestyle`` (or
``ls``) keyword argument, in line with the `upstream change in Matplotlib
<https://matplotlib.org/api/prev_api_changes/api_changes_3.1.0.html#passing-a-line2d-s-drawstyle-together-with-the-linestyle-is-deprecated>`_.
(:pull:`3274`)
By `Elliott Sales de Andrade <https://github.com/QuLogic>`_

New Features
~~~~~~~~~~~~
Expand Down
18 changes: 9 additions & 9 deletions xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def line(
return primitive


def step(darray, *args, where="pre", linestyle=None, ls=None, **kwargs):
def step(darray, *args, where="pre", drawstyle=None, ds=None, **kwargs):
"""
Step plot of DataArray index against values

Expand Down Expand Up @@ -359,16 +359,16 @@ def step(darray, *args, where="pre", linestyle=None, ls=None, **kwargs):
if where not in {"pre", "post", "mid"}:
raise ValueError("'where' argument to step must be " "'pre', 'post' or 'mid'")

if ls is not None:
if linestyle is None:
linestyle = ls
if ds is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise an error if linestyle or ls is in kwargs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linestyle and ls are still valid things to pass; you just can't mix draw styles into the string.

if drawstyle is None:
drawstyle = ds
else:
raise TypeError("ls and linestyle are mutually exclusive")
if linestyle is None:
linestyle = ""
linestyle = "steps-" + where + linestyle
raise TypeError("ds and drawstyle are mutually exclusive")
if drawstyle is None:
drawstyle = ""
drawstyle = "steps-" + where + drawstyle

return line(darray, *args, linestyle=linestyle, **kwargs)
return line(darray, *args, drawstyle=drawstyle, **kwargs)


def hist(
Expand Down
4 changes: 2 additions & 2 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def _resolve_intervals_1dplot(xval, yval, xlabel, ylabel, kwargs):
"""

# Is it a step plot? (see matplotlib.Axes.step)
if kwargs.get("linestyle", "").startswith("steps-"):
if kwargs.get("drawstyle", "").startswith("steps-"):

# Convert intervals to double points
if _valid_other_type(np.array([xval, yval]), [pd.Interval]):
Expand All @@ -476,7 +476,7 @@ def _resolve_intervals_1dplot(xval, yval, xlabel, ylabel, kwargs):
yval, xval = _interval_to_double_bound_points(yval, xval)

# Remove steps-* to be sure that matplotlib is not confused
del kwargs["linestyle"]
del kwargs["drawstyle"]

# Is it another kind of plot?
else:
Expand Down
4 changes: 4 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ def setUp(self):
def test_step(self):
self.darray[0, 0].plot.step()

@pytest.mark.parametrize("ds", ["pre", "post", "mid"])
def test_step_with_drawstyle(self, ds):
self.darray[0, 0].plot.step(drawstyle=ds)

def test_coord_with_interval_step(self):
"""Test step plot with intervals."""
bins = [-1, 0, 1, 2]
Expand Down