Skip to content

Commit 88cf7ff

Browse files
tacaswellQuLogic
authored andcommitted
Backport PR #23232: Fix passing stem markerfmt positionally when locs are not given
1 parent 02219ee commit 88cf7ff

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Passing *linefmt* positionally is undeprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Positional use of all formatting parameters in `~.Axes.stem` has been
5+
deprecated since Matplotlib 3.5. This deprecation is relaxed so that one can
6+
still pass *linefmt* positionally, i.e. ``stem(x, y, 'r')``.

lib/matplotlib/axes/_axes.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2853,12 +2853,15 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28532853
heads, = args
28542854
locs = np.arange(len(heads))
28552855
args = ()
2856+
elif isinstance(args[1], str):
2857+
heads, *args = args
2858+
locs = np.arange(len(heads))
28562859
else:
28572860
locs, heads, *args = args
2858-
if args:
2861+
if len(args) > 1:
28592862
_api.warn_deprecated(
28602863
"3.5",
2861-
message="Passing the linefmt parameter positionally is "
2864+
message="Passing the markerfmt parameter positionally is "
28622865
"deprecated since Matplotlib %(since)s; the "
28632866
"parameter will become keyword-only %(removal)s.")
28642867

lib/matplotlib/tests/test_axes.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -3703,16 +3703,24 @@ def test_stem(use_line_collection):
37033703

37043704

37053705
def test_stem_args():
3706+
def _assert_equal(stem_container, expected):
3707+
x, y = map(list, stem_container.markerline.get_data())
3708+
assert x == expected[0]
3709+
assert y == expected[1]
3710+
37063711
fig, ax = plt.subplots()
37073712

3708-
x = list(range(10))
3709-
y = list(range(10))
3713+
x = [1, 3, 5]
3714+
y = [9, 8, 7]
37103715

37113716
# Test the call signatures
3712-
ax.stem(y)
3713-
ax.stem(x, y)
3714-
ax.stem(x, y, linefmt='r--')
3715-
ax.stem(x, y, linefmt='r--', basefmt='b--')
3717+
_assert_equal(ax.stem(y), expected=([0, 1, 2], y))
3718+
_assert_equal(ax.stem(x, y), expected=(x, y))
3719+
_assert_equal(ax.stem(x, y, linefmt='r--'), expected=(x, y))
3720+
_assert_equal(ax.stem(x, y, 'r--'), expected=(x, y))
3721+
_assert_equal(ax.stem(x, y, linefmt='r--', basefmt='b--'), expected=(x, y))
3722+
_assert_equal(ax.stem(y, linefmt='r--'), expected=([0, 1, 2], y))
3723+
_assert_equal(ax.stem(y, 'r--'), expected=([0, 1, 2], y))
37163724

37173725

37183726
def test_stem_dates():

0 commit comments

Comments
 (0)