Skip to content

Commit

Permalink
Use drawstyle instead of linestyle in plot.step.
Browse files Browse the repository at this point in the history
Mixing the two is deprecated in Matplotlib 3.1, and breaks the doc build
if warnings are set to errors (which they are in new IPython sphinx
extensions.)
  • Loading branch information
QuLogic committed Mar 25, 2020
1 parent ec215da commit fb9adcb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
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:
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

0 comments on commit fb9adcb

Please sign in to comment.