Skip to content

Commit

Permalink
Make stem formatting parameters keyword only.
Browse files Browse the repository at this point in the history
This will allow to simplify the implementation because, currently,
`stem(*args, linefmt=None, ...)` still tries to resolve excess
positionally passed args, to *linefmt* and following parameters, which
is quite a bit of logic.

OTOH, since we have 3 formats, passing them positionally is already
difficult from a usability/readability perspective, because they can
easily be mixed up.
  • Loading branch information
timhoffm committed Sep 23, 2021
1 parent 1cec9c1 commit 88cdf1b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/api/next_api_changes/deprecations/21126-TH.rst
@@ -0,0 +1,2 @@
Passing formatting parameters positionally to ``stem()`` is deprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 changes: 6 additions & 0 deletions lib/matplotlib/axes/_axes.py
Expand Up @@ -2849,6 +2849,12 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
args = ()
else:
locs, heads, *args = args
if args:
_api.warn_deprecated(
"3.5",
message="Passing the linefmt parameter positionally is "
"deprecated since Matplotlib %(since)s; the "
"parameter will become keyword-only %(removal)s.")

if orientation == 'vertical':
locs, heads = self._process_unit_info([("x", locs), ("y", heads)])
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -3641,16 +3641,16 @@ def test_stem_args():
# Test the call signatures
ax.stem(y)
ax.stem(x, y)
ax.stem(x, y, 'r--')
ax.stem(x, y, 'r--', basefmt='b--')
ax.stem(x, y, linefmt='r--')
ax.stem(x, y, linefmt='r--', basefmt='b--')


def test_stem_dates():
fig, ax = plt.subplots(1, 1)
xs = [dateutil.parser.parse("2013-9-28 11:00:00"),
dateutil.parser.parse("2013-9-28 12:00:00")]
ys = [100, 200]
ax.stem(xs, ys, "*-")
ax.stem(xs, ys)


@pytest.mark.parametrize("use_line_collection", [True, False],
Expand Down

0 comments on commit 88cdf1b

Please sign in to comment.