Skip to content

Commit fb9adcb

Browse files
committed
Use drawstyle instead of linestyle in plot.step.
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.)
1 parent ec215da commit fb9adcb

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

doc/whats-new.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ v0.16.0 (unreleased)
2020

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

2530
New Features
2631
~~~~~~~~~~~~

xarray/plot/plot.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def line(
329329
return primitive
330330

331331

332-
def step(darray, *args, where="pre", linestyle=None, ls=None, **kwargs):
332+
def step(darray, *args, where="pre", drawstyle=None, ds=None, **kwargs):
333333
"""
334334
Step plot of DataArray index against values
335335
@@ -359,16 +359,16 @@ def step(darray, *args, where="pre", linestyle=None, ls=None, **kwargs):
359359
if where not in {"pre", "post", "mid"}:
360360
raise ValueError("'where' argument to step must be " "'pre', 'post' or 'mid'")
361361

362-
if ls is not None:
363-
if linestyle is None:
364-
linestyle = ls
362+
if ds is not None:
363+
if drawstyle is None:
364+
drawstyle = ds
365365
else:
366-
raise TypeError("ls and linestyle are mutually exclusive")
367-
if linestyle is None:
368-
linestyle = ""
369-
linestyle = "steps-" + where + linestyle
366+
raise TypeError("ds and drawstyle are mutually exclusive")
367+
if drawstyle is None:
368+
drawstyle = ""
369+
drawstyle = "steps-" + where + drawstyle
370370

371-
return line(darray, *args, linestyle=linestyle, **kwargs)
371+
return line(darray, *args, drawstyle=drawstyle, **kwargs)
372372

373373

374374
def hist(

xarray/plot/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def _resolve_intervals_1dplot(xval, yval, xlabel, ylabel, kwargs):
465465
"""
466466

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

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

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

481481
# Is it another kind of plot?
482482
else:

xarray/tests/test_plot.py

+4
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@ def setUp(self):
591591
def test_step(self):
592592
self.darray[0, 0].plot.step()
593593

594+
@pytest.mark.parametrize("ds", ["pre", "post", "mid"])
595+
def test_step_with_drawstyle(self, ds):
596+
self.darray[0, 0].plot.step(drawstyle=ds)
597+
594598
def test_coord_with_interval_step(self):
595599
"""Test step plot with intervals."""
596600
bins = [-1, 0, 1, 2]

0 commit comments

Comments
 (0)